Sunday 3 December 2017

"/var/lib/pgsql/data" is missing or empty. in postgresql Database

Problem: When trying to check the service status of  postgresql  as root on RHEL 7 server, i got the following error message

[root@localhost RHEL-7.0 Server.x86_64]# systemctl status postgresql.service 
postgresql.service - PostgreSQL database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled)
   Active: failed (Result: exit-code) since Mon 2017-12-04 01:37:16 EST; 7s ago
  Process: 14151 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=1/FAILURE)

Dec 04 01:37:16 localhost.localdomain postgresql-check-db-dir[14151]: "/var/lib/pgsql/data" is missing or empty.
Dec 04 01:37:16 localhost.localdomain postgresql-check-db-dir[14151]: Use "postgresql-setup initdb" to initialize the database cluster.
Dec 04 01:37:16 localhost.localdomain postgresql-check-db-dir[14151]: See /usr/share/doc/postgresql-9.2.7/README.rpm-dist for mor...ion.
Dec 04 01:37:16 localhost.localdomain systemd[1]: postgresql.service: control process exited, code=exited status=1
Dec 04 01:37:16 localhost.localdomain systemd[1]: Failed to start PostgreSQL database server.
Dec 04 01:37:16 localhost.localdomain systemd[1]: Unit postgresql.service entered failed state.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost RHEL-7.0 Server.x86_64]#

Reason:
initdb creates a new PostgreSQL database cluster. A database cluster is a collection of databases that are managed by a single server instance.
Creating a database cluster consists of creating the directories in which the database data will live, generating the shared catalog tables (tables that belong to the whole cluster rather than to any particular database), and creating the template1 and postgres databases. When you later create a new database, everything in the template1 database is copied. (Therefore, anything installed in template1 is automatically copied into each database created later.) The postgres database is a default database meant for use by users, utilities and third party applications.


Solution:


[root@localhost RHEL-7.0 Server.x86_64]# service postgresql initdb
Hint: the preferred way to do this is now "postgresql-setup initdb"
Initializing database ... OK

[root@localhost RHEL-7.0 Server.x86_64]#

[root@localhost RHEL-7.0 Server.x86_64]# systemctl stop postgresql.service
[root@localhost RHEL-7.0 Server.x86_64]# systemctl start postgresql.service
[root@localhost RHEL-7.0 Server.x86_64]# systemctl status postgresql.service
postgresql.service - PostgreSQL database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled)
   Active: active (running) since Mon 2017-12-04 01:40:51 EST; 4s ago
  Process: 46413 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=0/SUCCESS)
  Process: 46408 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 46418 (postgres)
   CGroup: /system.slice/postgresql.service
           ├─46418 /usr/bin/postgres -D /var/lib/pgsql/data -p 5432
           ├─46419 postgres: logger process 
           ├─46421 postgres: checkpointer process 
           ├─46422 postgres: writer process 
           ├─46423 postgres: wal writer process 
           ├─46424 postgres: autovacuum launcher process 
           └─46425 postgres: stats collector process 

Dec 04 01:40:50 localhost.localdomain systemd[1]: Starting PostgreSQL database server...
Dec 04 01:40:51 localhost.localdomain systemd[1]: Started PostgreSQL database server.
[root@localhost RHEL-7.0 Server.x86_64]#

1 comment: