Enable the PostgreSQL cluster/service during OS reboot.
Installed under ==> /usr/pgsql-13/bin/postgresql-13-setup
postgresql-13-setup ===>
postgresql-13-setup ===>
Some information about this script.
1)This script is created/given/installed as part of postgres server/database installation.
2)During installation its create the service file under =======> cd /usr/lib/systemd/system
cat postgresql-13.service ====> this is the define all parameter to start the service while start OS.
while reboot if we enable the service then ,script executed & start services.
3)We can run postgresql-13.service as foreground process. below is snippets from postgresql-13.service to start the service.
-bash-4.2$ /usr/pgsql-13/bin/postgresql-13-check-db-dir /var/lib/pgsql/13/data/
-bash-4.2$ /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
In short this command used by OS process to start the PostgreSQL as service.
If you run on server level
-bash-4.2$ /usr/pgsql-13/bin/postgresql-13-check-db-dir /var/lib/pgsql/13/data/
-bash-4.2$ /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
-bash-4.2$ /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
2022-01-16 06:34:05.983 IST [10369] LOG: redirecting log output to logging collector process
2022-01-16 06:34:05.983 IST [10369] HINT: Future log output will appear in directory "log".
its will run as foreground process.
For normal user ===> Manually DBA will use below command to start/stop cluster services.
/usr/pgsql-13/bin/pg_ctl start
This command also start the cluster/database services.
Both above command do same things.
-bash-4.2$ ps -ef|grep postgres
postgres 10369 10200 0 06:34 pts/3 00:00:00 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
postgres 10370 10369 0 06:34 ? 00:00:00 postgres: logger
postgres 10372 10369 0 06:34 ? 00:00:00 postgres: checkpointer
postgres 10373 10369 0 06:34 ? 00:00:00 postgres: background writer
postgres 10374 10369 0 06:34 ? 00:00:00 postgres: walwriter
postgres 10375 10369 0 06:34 ? 00:00:00 postgres: autovacuum launcher
postgres 10376 10369 0 06:34 ? 00:00:00 postgres: stats collector
postgres 10377 10369 0 06:34 ? 00:00:00 postgres: logical replication launcher
-bash-4.2$ ps -ef|grep postgres
postgres 10369 10200 0 06:34 pts/3 00:00:00 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
postgres 10370 10369 0 06:34 ? 00:00:00 postgres: logger
postgres 10372 10369 0 06:34 ? 00:00:00 postgres: checkpointer
postgres 10373 10369 0 06:34 ? 00:00:00 postgres: background writer
postgres 10374 10369 0 06:34 ? 00:00:00 postgres: walwriter
postgres 10375 10369 0 06:34 ? 00:00:00 postgres: autovacuum launcher
postgres 10376 10369 0 06:34 ? 00:00:00 postgres: stats collector
postgres 10377 10369 0 06:34 ? 00:00:00 postgres: logical replication launcher
4)Optionally initialize the database
we can use the postgresql-13-setup script to create new database service. like dbca in oracle.
Below is usage of the script.
Usage: /usr/pgsql-13/bin/postgresql-13-setup {initdb|check_upgrade|upgrade} [SERVICE_NAME]
Script is aimed to help sysadmin with basic database cluster administration.
The SERVICE_NAME is used for selection of proper unit configuration file; Formore info and howto/when use this script please look at README.rpm-dist file.
The 'postgresql' string is used when no SERVICE_NAME is explicitly passed.
Available operation mode:
initdb Create a new PostgreSQL database cluster. This is usually the
first action you perform after PostgreSQL server installation.
check_upgrade Checks whether the old cluster can be upgraded to the new version
or not.
upgrade Upgrade PostgreSQL database cluster to be usable with new server. Use this if you upgraded your PostgreSQL server to
newer major version (currently from 12 to 13).
4)Enable postgresql-13-setup script as cluster starup service while OS starup.
initdb Create a new PostgreSQL database cluster. This is usually the
first action you perform after PostgreSQL server installation.
check_upgrade Checks whether the old cluster can be upgraded to the new version
or not.
upgrade Upgrade PostgreSQL database cluster to be usable with new server. Use this if you upgraded your PostgreSQL server to
newer major version (currently from 12 to 13).
Syntax to create Database./usr/pgsql-13/bin/postgresql-13-setup initdb4)Enable postgresql-13-setup script as cluster starup service while OS starup.
[root@pgnode1 ~]# systemctl enable postgresql-13
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-13.service
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-13.service
to /usr/lib/systemd/system/postgresql13.service
once enable its create symlink as shown in above.
[root@pgnode1 ~]# systemctl status postgresql-13.service
● postgresql-13.service - PostgreSQL 13 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
Active: inactive (dead)==========> dead
Now lets start the postgres service to start postgres database/cluster while startup the OS.
systemctl start postgresql-13
● postgresql-13.service - PostgreSQL 13 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
Active: inactive (dead)==========> dead
Now lets start the postgres service to start postgres database/cluster while startup the OS.
systemctl start postgresql-13
[root@pgnode1 ~]# systemctl start postgresql-13
[root@pgnode1 ~]# systemctl status postgresql-13
● postgresql-13.service - PostgreSQL 13 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2022-01-16 07:07:01 IST; 29s ago
Docs: https://www.postgresql.org/docs/13/static/
Process: 11016 ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 11021 (postmaster)
CGroup: /system.slice/postgresql-13.service
├─11021 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
├─11025 postgres: logger
├─11027 postgres: checkpointer
├─11028 postgres: background writer
├─11029 postgres: walwriter
├─11030 postgres: autovacuum launcher
├─11031 postgres: stats collector
└─11032 postgres: logical replication launcher
Look it will start the PostgreSQL background process and database cluster also.
[root@pgnode1 ~]# systemctl status postgresql-13
● postgresql-13.service - PostgreSQL 13 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2022-01-16 07:07:01 IST; 29s ago
Docs: https://www.postgresql.org/docs/13/static/
Process: 11016 ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 11021 (postmaster)
CGroup: /system.slice/postgresql-13.service
├─11021 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
├─11025 postgres: logger
├─11027 postgres: checkpointer
├─11028 postgres: background writer
├─11029 postgres: walwriter
├─11030 postgres: autovacuum launcher
├─11031 postgres: stats collector
└─11032 postgres: logical replication launcher
Look it will start the PostgreSQL background process and database cluster also.
4)Now check database login
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
postgres=# select name, setting from pg_settings where name like 'data_directory';
name | setting
----------------+------------------------
data_directory | /var/lib/pgsql/13/data
(1 row)
Now successfully login to the database.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
postgres=# select name, setting from pg_settings where name like 'data_directory';
name | setting
----------------+------------------------
data_directory | /var/lib/pgsql/13/data
(1 row)
Now successfully login to the database.