I wanted to install it easily with package management (yum, apt, etc.), but I had the opportunity to install PostgreSQL on CentOS 7.5 for the first time in about 20 years from the source code, so I made a note.
# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
For the time being, I was able to do it by the following procedure.
Prepare a dedicated account to use PostgreSQL. Create an account name "postgres" by also specifying your home directory.
# useradd -m -d /home/postgres postgres
You will also set a password.
# passwd postgres
Change password for user postgres.
new password:
Please re-enter your new password:
passwd:All authentication tokens have been successfully renewed.
Prepare the necessary tools to get the source code and compile it. (I will definitely enjoy yum here!)
# yum -y groupinstall Development Tools
# yum -y install readline-devel
# yum -y install zlib-devel zlib wget vim
Get it with wget. I was able to check the version list on the official site, so I used v12.4 this time. PostgreSQL File Browser
# wget https://ftp.postgresql.org/pub/source/v12.4/postgresql-12.4.tar.gz
...
100%[==========================================================>] 27,070,070 564KB/s time 72s
2020-09-30 17:46:23 (365 KB/s) - `postgresql-12.4.tar.gz'Save to[27070070/27070070]
Since it is hardened with tar, it expands softly.
# tar xvfz postgresql-12.4.tar.gz
...
postgresql-12.4/configure.in
postgresql-12.4/INSTALL
Compiling the extracted source code. (I feel nostalgic after working for the first time in 20 years)
# cd postgresql-12.4
# ./configure
# make
# make install
...
PostgreSQL installation complete.
After the installation work, PostgreSQL is operated with the account "postgres" created earlier.
# exit
login:postgres
Password:
$
Since the PATH to the installed PostgreSQL does not pass, edit .bash_profile etc. Put it in your PATH.
$ vim .bash_profile
Editing contents ↓
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH=/usr/local/pgsql/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/pgsql/lib:$LD_LIBRARY_PATH
Logout → You can log in again, but it was troublesome, so reload it with source.
$ source .bash_profile
Let's check if there are any commands related to PostgreSQL.
$ which psql
/usr/local/pgsql/bin/psql
$ which initdb
/usr/local/pgsql/bin/initdb
I'm on the PATH!
In the case of PostgreSQL, it is necessary to create a database cluster first, so create it while specifying the directory.
$ initdb -D /home/postgres/data --no-locale
...
Success. You can now start the database server using:
pg_ctl -D /home/postgres/data -l logfile start
$ ls -l /home/postgres
4 in total
drwx------.19 postgres postgres 4096 September 30 18:12 data
Specify the created database cluster and start PostgreSQL.
$ pg_ctl start -D /home/postgres/data
...
done
server started
$
Since it started, I will try to hit the SQL statement. Connect with psql for the time being.
$ psql
psql (12.4)
Type "help" for help.
postgres=#
It seems that you can enter SQL statements, so you can enter it as a trial.
postgres=# SELECT now();
now
-------------------------------
2020-09-30 18:20:14.031968+09
(1 row)
postgres=# \q
$
done. It's been a while> PostgreSQL
To be honest, it's easy to prepare with a package management tool. If you need to compile from the source code for some reason, you have to work while looking at the manual, so let's do our best!
Chapter 16 Install from Source Code psql document
Recommended Posts