2

I am about to restart postgresql 12 service running on Ubuntu 18. First, I check it's status : sudo service postgresql status. Its says :

postgresql.service - PostgreSQL RDBMS
 Loaded: loaded (/lib/systemd/system/postgresql.service; disabled; vendor pres
 Active: inactive (dead)
lines 1-3/3 (END)...skipping...
postgresql.service - PostgreSQL RDBMS
 Loaded: loaded (/lib/systemd/system/postgresql.service; disabled; vendor preset: enabled)
 Active: inactive (dead)

Although it appears to be inactive, but I still can connect.

Then I run another checking : systemctl status postgresql@12-main. it says :

root@db-services:/# systemctl status postgresql@12-main
くろまる [email protected] - PostgreSQL Cluster 12-main
 Loaded: loaded (/etc/systemd/system/[email protected]; enabled; vendor preset: enabled)
 Drop-In: /etc/systemd/system/[email protected]
 └─override.conf
 Active: active (running) since Mon 2022年06月13日 09:02:25 WIB; 5 months 27 days ago
 Main PID: 5807 (postgres)
 Tasks: 86 (limit: 4915)
 CGroup: /system.slice/system-postgresql.slice/[email protected]
 ├─ 1586 postgres: 12/main: postgres db_sync 10.100.3.248(61414) idle
 ├─ 1588 postgres: 12/main: postgres db_sync 10.100.3.248(61415) idle
 ├─ 1606 postgres: 12/main: docreg db_docreg 10.100.8.150(18385) idle
 ├─ 1607 postgres: 12/main: docreg db_docreg 10.100.8.150(18399) idle
 ├─ 1608 postgres: 12/main: docreg db_docreg 10.100.8.150(18401) idle
 ├─ 1609 postgres: 12/main: docreg db_docreg 10.100.8.150(18421) idle
 ├─ 2592 postgres: 12/main: docudigtl db_docudigtl 10.100.8.112(34956) idle
 ├─ 3518 postgres: 12/main: docudigtl db_docudigtl 127.0.0.1(48290) idle
 ├─ 5150 postgres: 12/main: docudigtl db_docudigtl 10.100.7.114(61504) idle
 ├─ 5807 /usr/lib/postgresql/12/bin/postgres -D /data/postgresql/12/main -c config_file=/etc/postgresql/12/main/postgresql.co
 ├─ 5883 postgres: 12/main: docudigtl db_docudigtl 127.0.0.1(48626) idle
 ├─ 6316 postgres: 12/main: docudigtl db_docudigtl 127.0.0.1(48704) idle
 ├─ 7049 postgres: 12/main: docudigtl db_docudigtl 127.0.0.1(48870) idle
 ├─ 7986 postgres: 12/main: docudigtl db_docudigtl 10.100.7.114(56240) idle
 ├─ 8146 postgres: 12/main: docudigtl db_docudigtl 10.100.8.114(47432) idle
 ├─ 8183 postgres: 12/main: docudigtl db_docudigtl 127.0.0.1(49022) idle
 ├─ 8360 postgres: 12/main: docudigtl db_docudigtl 127.0.0.1(49036) idle
 ├─ 8445 postgres: 12/main: docudigtl db_docudigtl 10.100.8.114(47478) idle
 ├─ 9590 postgres: 12/main: docudigtl db_docudigtl 10.100.8.106(56094) idle
 ├─ 9687 postgres: 12/main: docudigtl db_docudigtl 10.100.8.112(50980) idle
 ├─10148 postgres: 12/main: docudigtl db_docudigtl 127.0.0.1(40646) idle
 ├─10324 postgres: 12/main: docudigtl db_docudigtl 127.0.0.1(40680) idle
 ├─11079 postgres: 12/main: docudigtl db_docudigtl 127.0.0.1(49496) idle
 ├─11602 postgres: 12/main: docudigtl db_docudigtl 127.0.0.1(58152) idle
 ├─11886 postgres: 12/main: docudigtl db_docudigtl 127.0.0.1(44674) idle
 ├─12106 postgres: 12/main: docudigtl db_docudigtl 127.0.0.1(49618) idle
 ├─13112 postgres: 12/main: docudigtl db_docudigtl 10.100.6.145(55014) idle
 ├─13122 postgres: 12/main: docudigtl db_docudigtl 10.100.6.145(55015) idle
 ├─13145 postgres: 12/main: docudigtl db_mysapk 10.100.6.145(55016) idle
 ├─13202 postgres: 12/main: docudigtl db_docudigtl 10.100.7.114(62073) idle
 ├─13945 postgres: 12/main: checkpointer
 ├─13946 postgres: 12/main: background writer
 ├─13947 postgres: 12/main: walwriter
 ├─13948 postgres: 12/main: autovacuum launcher
 ├─13949 postgres: 12/main: stats collector
 ├─13950 postgres: 12/main: logical replication launcher

So it is actually active !

Then I do sudo service --status-all | grep postgresql. It says :

[ - ] postgresql
  1. Whats the difference between systemctl restart postgresql@12-main VS sudo service postgresql restart?
  2. Which one should I use for restart : systemctl restart postgresql@12-main OR sudo service postgresql restart ?

For comparison, on another server, if I do sudo service postgresql status. It says :

postgresql.service - PostgreSQL RDBMS
 Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
 Active: active (exited) since Mon 2022年12月05日 18:37:03 WIT; 4 days ago
 Process: 22666 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 22666 (code=exited, status=0/SUCCESS)
Dec 05 18:37:03 db-profile-mtr systemd[1]: Starting PostgreSQL RDBMS...
Dec 05 18:37:03 db-profile-mtr systemd[1]: Started PostgreSQL RDBMS.

And when I do systemctl status postgresql@12-main, it says :

[email protected] - PostgreSQL Cluster 12-main
 Loaded: loaded (/etc/systemd/system/[email protected]; enabled-runtime; vendor preset: enabled)
 Active: active (running) since Mon 2022年12月05日 18:37:03 WIT; 4 days ago
 Process: 22609 ExecStop=/usr/bin/pg_ctlcluster --skip-systemctl-redirect -m fast 12-main stop (code=exited, status=0/SUCCESS)
 Process: 22631 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 12-main start (code=exited, status=0/SUCCESS)
 Main PID: 22637 (postgres)
 Tasks: 119 (limit: 4915)
 CGroup: /system.slice/system-postgresql.slice/[email protected]
 ├─ 417 postgres: 12/main: refer db_ref 10.100.9.50(53216) idle
 ├─ 965 postgres: 12/main: refer db_ref 10.100.9.50(53514) idle
 ├─ 1709 postgres: 12/main: profiling db_profile 127.0.0.1(34158) idle
 ...many proceses all the way down

Then I do sudo service --status-all | grep postgresql. And it says :

 [ + ] postgresql

Need advice / help. Thanks

asked Dec 9, 2022 at 19:10

1 Answer 1

2

Probably neither, as there are actually two variables:

  1. Command.
    • The service command is legacy from SysVInit.
    • The systemctl comes with SystemD and replaces SysVInit; use it.
  2. Postgresql services on Ubuntu.
    • postgresql.service controls all Postgresql instances.
    • [email protected] is a single instance; there could be multiple.

To restart all instances: sudo systemctl restart postgresql.

There's a longer explanation on AskUbuntu.

answered Dec 9, 2022 at 19:39
1
  • Finally I did it using sudo service postgresql restart. Now when I do sudo service postgresql status it shows : postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; disabled; vendor preset: enabled) Active: active (exited) since Sun 2022年12月11日 00:38:06 WIB; 11s ago Process: 3095 ExecStart=/bin/true (code=exited, status=0/SUCCESS) Main PID: 3095 (code=exited, status=0/SUCCESS) . All is well. Thanks @EsaJokinen. Commented Dec 10, 2022 at 17:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.