mayosten
mayosten

Reputation: 734

postgresql-setup command and postgres service not found on AWS Linux

I have been configuring an EC2 instance with postgreSQL according to the steps outlined in this tutorial. I am using AWS Linux 2018-03 and have installed postgres92 via the following:

$ sudo yum install postgresql postgresql-server postgresql-devel postgresql-contrib postgresql-docs

My understanding is that I should be able to directly initialize postgres with:

$ sudo postgresql-setup initdb

as noted in this related question (note: it would appear I need to conduct this step as well, I'm unable to run postgres as a service just yet). However, calls to postgresql-setup return:

sudo: postgresql-setup: command not found

I've also tried a find / postgresql-setup just to see if this is hanging around on the system somewhere, but this turns up nothing. I am unable to start postgres via sudo service postgres ... commands, as the service is not yet recognized. I have confirmed that the service is not running via:

$ sudo service postgres status

which just tells me that the service is unrecognized and I have also checked with a ps -ef | grep postgres, which also turns up nothing.

My question remains, how do I initialize postgres so that it can be recognized as a service given that postgresql-setup cannot be located? Thanks.

Upvotes: 3

Views: 7275

Answers (1)

mayosten
mayosten

Reputation: 734

I was able to resolve my issue with a slight modification to the configuration instructions found in the referenced tutorials/questions.

1. Different calls for initializing database

It appears postgresql made some fairly major name changes around v9 such that postgresql-setup --initdb and postgresql-setup initdb are now equivalent to initdb.

First, might need to change permissions/ownership to the data directory. Typical user is postgres.

$ sudo chmod 775 /var/lib/pgsql92
$ sudo chown USER /var/lib/pgsql92

The initialize the database with:

$ initdb -D /var/lib/pgsql92

May have to sudo -u USER ... to run this depending on current role, but I finally received:

Success. You can now start the database server using:

postgres -D /var/lib/pgsql or pg_ctl -D /var/lib/pgsql -l logfile start

2. Different service name

Finally, this post proved to be extremely helpful in diagnosing issues surrounding postgres as an unrecognized service. Many popular tutorials out there suggest sudo service postgres start, but a check of run-level-3 services (not that I know what that is, but this Gunther Schadow guy sure does) with

$ ls -1 /etc/rc.d/rc3.d | fgrep post

shows that we should really be calling the service as postgresql. If we do the following:

$ sudo service postgresql initdb
$ sudo service postgresql start

we actual get the service to run and the rest of the process is just configuration through psql, which works as expected.

Upvotes: 2

Related Questions