Install PostgreSQL11.6 and start multiple instances. Also, create a startup script for each instance so that it can be started / stopped individually.
Instance ①
pgsql-5432
Port: 5432
/data/pgsql-5432
Instance ②
pgsql-5433
Port 5433
/data/pgsql-5433
This time, we will install version 11, so we will add a repository.
$ yum --disablerepo=\* --enablerepo=centos-media list
$ yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
$ yum -y install postgresql11-server postgresql11-contrib
$ rpm -qa |grep postgres
$ ls -l /usr/pgsql-11/
Add PATH to postgres user.
$ su - postgres
$ vi ./bashrc
export PATH=$PATH:/usr/pgsql-11/bin
export PGDATA=/data/pgsql-5432
export PATH
export PGDATA
$ source bashrc
Create the first instance pgsql-5432.
Create an instance in the directory "/ data / pgsql-5432" with the initdb command.
$ initdb --pgdata=/data/pgsql-5432
$ cat /data/pgsql-5432/PG_VERSION
11
Execute the pg_ctl command to confirm the startup of the instance.
$ su postgres
$ /usr/pgsql-11/bin/pg_ctl -D /data/pgsql-5432 start
$ /usr/pgsql-11/bin/pg_ctl -D /data/pgsql-5432 stop
$ exit
Duplicate the startup script created during installation and edit it for instance ①.
$ cd /usr/lib/systemd/system/
$ cp -p postgresql.service postgresql-5432.service
$ vi /usr/lib/systemd/system/postgresql-5432.service
Environment=PGDATA=/data/pgsql-5432/
Set the service stop / start of instance ①, and if necessary, automatic start.
$ systemctl daemon-reload
$ systemctl status postgresql-5432.service
$ systemctl start postgresql-5432.service
$ systemctl stop postgresql-5432.service
$ systemctl status postgresql-5432.service
$ systemctl enable postgresql-5432.service
$ systemctl list-unit-files |grep postgres
Create the first instance pgsql-5433. Just change the directory path of the procedure executed in "instance ①".
Create an instance in the directory "/ data / pgsql-5433" with the initdb command.
$ initdb --pgdata=/data/pgsql-5433
$ cat /data/pgsql-5433/PG_VERSION
11
Execute the pg_ctl command to confirm the startup of the instance.
$ su postgres
$ /usr/pgsql-11/bin/pg_ctl -D /data/pgsql-5432 start
$ /usr/pgsql-11/bin/pg_ctl -D /data/pgsql-5432 stop
$ exit
Duplicate the startup script created during installation and edit it for instance ②.
$ cd /usr/lib/systemd/system/
$ cp -p postgresql.service postgresql-5433.service
$ vi /usr/lib/systemd/system/postgresql-5433.service
Environment=PGDATA=/data/pgsql-5432/
Set the service stop / start of instance ②, and if necessary, automatic start.
$ systemctl daemon-reload
$ systemctl status postgresql-5433.service
$ systemctl start postgresql-5433.service
$ systemctl stop postgresql-5433.service
$ systemctl status postgresql-5433.service
$ systemctl enable postgresql-5433.service
$ systemctl list-unit-files |grep postgres
Change the port used by each instance. This time, only instance ② is changed.
$ vi /data/pgsql-5433/postgresql.conf
#port = 5432
port = 5433
Launch instances individually.
$ systemctl start postgresql-5432.service
$ systemctl status postgresql-5432.service
$ systemctl start postgresql-5433.service
$ systemctl status postgresql-5433.service
Check the process of each instance.
$ ps -ef |grep pgsql
postgres 28435 1 0 Feb09 ? 00:00:02 /usr/pgsql-11/bin/postmaster -D /data/pgsql-5432/
postgres 28456 1 0 Feb09 ? 00:00:01 /usr/pgsql-11/bin/postmaster -D /data/pgsql-5433/
Make sure each instance is running on the specified port.
$ ss -anp |grep 5432
~~~
tcp LISTEN 0 128 *:5432 *:* users:(("postmaster",pid=28435,fd=3))
~~~
$ ss -anp |grep 5433
~~~
tcp LISTEN 0 128 *:5433 *:* users:(("postmaster",pid=28456,fd=3))
~~~
All you have to do is set it for each instance!
$ ll /data/pgsql-5432
$ ll /data/pgsql-5433
that's all.
Recommended Posts