How to figure out if PostgreSQL database is running

You have OpenNMS installed but it won’t start due to (currently) unknown reasons.

The PostgreSQL database is extentially important for OpenNMS.

Here is a list of commands to check if it’s running.

Check if PostgreSQL is listening on port 5432:

[11:20]root@onms:~# ss -tulpn | grep 5432
tcp    LISTEN     0      128      :::5432                 :::*                   users:(("docker-proxy",pid=26410,fd=4))

Check systemd status

Depending on the version you are using (in this case 9.5):

[10:24]root@onms:/# systemctl status postgresql@9.5-main.service 
● postgresql@9.5-main.service - PostgreSQL Cluster 9.5-main
   Loaded: loaded (/lib/systemd/system/postgresql@.service; disabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-02-22 10:24:12 UTC; 58s ago
  Process: 20941 ExecStart=postgresql@%i --skip-systemctl-redirect %i start (code=exited, status=0/SUCCESS)
 Main PID: 20948 (postgres)
   CGroup: /system.slice/system-postgresql.slice/postgresql@9.5-main.service
           ├─20948 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c config_file=/etc/postgresql/9.5/main/postgresql.conf
           ├─20950 postgres: checkpointer process                                                                                              
           ├─20951 postgres: writer process                                                                                                    
           ├─20952 postgres: wal writer process                                                                                                
           ├─20953 postgres: autovacuum launcher process                                                                                       
           ├─20954 postgres: stats collector process                                                                                           
           ├─21532 postgres: opennms opennms 127.0.0.1(49850) idle                                                                             
           ├─21533 postgres: opennms opennms 127.0.0.1(49852) idle                                                                             
           ├─21534 postgres: opennms opennms 127.0.0.1(49854) idle                                                                             
           ├─21535 postgres: opennms opennms 127.0.0.1(49856) idle                                                                             
           ├─21536 postgres: opennms opennms 127.0.0.1(49858) idle                                                                             
           ├─21537 postgres: opennms opennms 127.0.0.1(49860) idle                                                                             
           ├─21538 postgres: opennms opennms 127.0.0.1(49862) idle                                                                             
           ├─21539 postgres: opennms opennms 127.0.0.1(49864) idle                                                                             
           ├─21540 postgres: opennms opennms 127.0.0.1(49866) idle                                                                             
           ├─21541 postgres: opennms opennms 127.0.0.1(49868) idle                                                                             
           └─21542 postgres: opennms opennms 127.0.0.1(49870) idle                                                                             

Feb 22 10:24:09 onms systemd[1]: Starting PostgreSQL Cluster 9.5-main...
Feb 22 10:24:12 onms systemd[1]: Started PostgreSQL Cluster 9.5-main.

Check if connection to PostgreSQL database is working

If this works you will get a list of all tables in OpenNMS database.

[10:36]root@onms:/# psql -h localhost -p 5432 -U opennms -P pager -c "\d"
Password for user opennms: 
                          List of relations
 Schema |                 Name                  |   Type   |  Owner  
--------+---------------------------------------+----------+---------
 public | accesslocks                           | table    | opennms
 public | accesspoints                          | table    | opennms
 public | acks                                  | table    | opennms
....
...
..
1 Like