Using postgresql in non daemon way

Posted on Dec 12, 2021

I have a preference against installing servers locally and running them as systemd services, which is why I’m a big fan of Docker.

However, there are times when I simply want to use servers as specific apps, without having to go through a system-wide installation, even with docker.

Take #postgresql as an example. A typical installation creates a user, installs files in your root directories, changes ownerships, creates service files, and so on.

Today, I aimed to run PostgreSQL without turning it into a systemd service. It’s actually simpler than you might think. Here are the steps:

  1. Download the executable (I used nix for this).

  2. Create a directory for PostgreSQL data.

  3. Apply the appropriate permissions to the folders.

  4. Run it!

adduser postgres #create user from ui in macos
su postgres
mkdir ./var/data
./psql/initdb ./var/data -U postgres -W
#write password
./bin/postgres -D var/pgsql/data -k .
./bin/psql -h
#its ok now, let create a db
./bin/createdb hedefim -h
#you can create another super user
./bin/createuser -s hedefim_user -W -h
#write new password

#you can now connect the database with your new user
./bin/psql -U hedefim_user -W hedefim -h

how its easy, right.

talk soon.

comments powered by Disqus