22

I'm using arch linux (4.8.13-1-ARCH). I'm trying to set up PostgreSQL as instructed here.

After performing

[postgres@BitBox ~]$ initdb --locale $LANG -E UTF8 -D '/var/lib/postgres/data'
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgres/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

pg_ctl -D /var/lib/postgres/data -l logfile start

successfully, I returned to the my regular user using exit command.

[postgres@BitBox ~]$ exit
logout

Then, while trying to start postgresql.service, I got the following error:

[code_master5@BitBox ~]$ sudo systemctl start postgresql.service
Failed to start postgresql.service: Unit postgresql.service not found.

I'm not even getting the status of the service:

[code_master5@BitBox ~]$ sudo systemctl status postgresql.service
Unit postgresql.service could not be found.

I'm stuck!

1
  • What command or commands did you use to install postgresql? Jan 26, 2017 at 18:20

8 Answers 8

30

Try this:

service postgresql-10.service restart
service postgresql-XX.service restart
2
  • 2
    OP seems to be using RHEL7 or CentOS7, as indicated by the systemctl commands. If so, the service ... restart commands won't work.
    – JohnG
    Jan 11, 2019 at 18:44
  • For Manjaro Linux / ArchLinux: systemctl restart postgresql.service Aug 14, 2020 at 17:07
20

Finally, I figured this one out. There was already a file present

/usr/lib/systemd/system/postgresql-9.6.service

So, may be due to the presence of this file, I was not able to start postgresql.service. Then I tried to start postgresql-9.6.service as follows:

[code_master5@BitBox ~]$ sudo systemctl start postgresql-9.6.service
Failed to start postgresql-9.6.service: Unit postgresql-9.6.service not found.

And, as you can see the output, again it failed.

I simply deleted the file using sudo as I thought may be postgresql.service file is not being created by relevant program due to the presence of this file. Then I restarted the system. It's working fine since then, as you can see the output below:

[code_master5@BitBox ~]$ sudo systemctl status postgresql.service
[sudo] password for code_master5: 
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor p
Active: active (running) since Sat 2017-01-28 09:31:30 IST; 7h ago
Main PID: 342 (postgres)
Tasks: 6 (limit: 4915)
CGroup: /system.slice/postgresql.service
       ├─342 /usr/bin/postgres -D /var/lib/postgres/data
       ├─358 postgres: checkpointer process   
       ├─359 postgres: writer process   
       ├─360 postgres: wal writer process   
       ├─361 postgres: autovacuum launcher process   
       └─362 postgres: stats collector process   

Jan 28 09:31:26 BitBox systemd[1]: Starting PostgreSQL database server...
Jan 28 09:31:28 BitBox postgres[340]: FATAL:  the database system is starting up
Jan 28 09:31:28 BitBox postgres[340]: LOG:  database system was shut down at 201
Jan 28 09:31:29 BitBox postgres[340]: FATAL:  the database system is starting up
Jan 28 09:31:29 BitBox postgres[340]: LOG:  MultiXact member wraparound protecti
Jan 28 09:31:29 BitBox postgres[340]: LOG:  database system is ready to accept c
Jan 28 09:31:29 BitBox postgres[340]: LOG:  autovacuum launcher started
Jan 28 09:31:30 BitBox systemd[1]: Started PostgreSQL database server.

I would surely like to warn all those having same problem. Please do whatever I did at your own risk. Since these are system files. Messing with these can spoil your weekend!

I am still a bit confused on this though. Explanations are welcome!

0
12

I found these two commands very handy. Although this post is old, maybe others will be benefited from this in the future.

systemctl list-units|grep postgresql
service postgresql-12.service restart
0
2

For PostGres 9.4.12, I tried the following and it worked:

./pg_ctl start

You can check the status of it:

./pg_ctl status
2

I use this command:

$ /etc/init.d/postgresql start
1

I know this post is hold, but for some people that might pass by, I found the solution being this (not deleting sys file but just reload the daemon after installation to update service file) :

$ sudo systemctl daemon-reload # load the updated service file from disk
$ sudo systemctl enable postgresql
$ sudo systemctl start postgresql
0

Next steps helped me on our test server.

Connect your server via SSH.

Then switch user:

$ sudo su - postgres

Check Postgres status:

pg_ctl status

Stop DB:

pg_ctl stop

Check if no server processes exist:

ps axf|grep postg

Start Postgres service:

sudo systemctl start postgresql.service 

OR

sudo systemctl start postgresql

Then check status:

systemctl status postgresql.service 

OR

systemctl status postgresql
0

Make sure to initialise the database.

sudo find / -name post*-setup sudo /usr/bin/postgresql-setup initdb

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.