Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Running Postgres with user privileges

Zohar Malamant edited this page Mar 1, 2021 · 1 revision

One can start a postgres server without needing to be sudo. These steps assume that you have postgres installed already, which is the case on Equinor RHEL 7 machines.

Setup postgres

# This will initialise a postgres database in your home directory.
# If your home is slow, consider putting it in /tmp or elsewhere.
initdb ~/pg

Now you need to edit the file ~/pg/postgresql.conf. Find, uncomment and edit the following settings

port = 54321  # defaults to 5432. We appended a 1 to differentiate from the system

unix_socket_directories = '/tmp'  # Remove the /var stuff. You don't have access to that directory.

Start postgres. Don't expect any output.

postgres -D ~/pg

Postgres will have created the files /tmp/.s.PGSQL.54321 and /tmp/.s.PGSQL.54321.lock. These are UNIX Domain Sockets that postgres clients use to communicate with the postgres server. Alternatively, it'll also listen to port 54321 on host localhost.

Use postgres

All the postgres utilities have the -h (host) and -p (port) options. You need to set them to connect to your postgres:

createuser -h /tmp -p 54321 -s ertuser  # Create ertuser as superuser (-s), using UNIX sockets
createdb -h localhost -p 54321 -O ertuser ertdb  # Create ertdb, with ertuser as owner (-O), using TCP sockets

(In my experience, initdb creates a superuser named as your user.)

$ createdb -h /tmp -p 54321 zom
$ psql -h /tmp -p 54321
psql (9.2.24)
Type "help" for help.

zom=# \password
Enter new password:
Enter it again:
zom=# \q

The connection string that ERT Storage uses will now be:

export ERT_STORAGE_DATABASE_URL=postgresql://user:password@localhost:54321/database

Assuming you've created a user user with password password, who owns (or can connect to, at least) the database database.

Clone this wiki locally