0

I want to run postgresql within a nix-shell. I followed the instructions on this page: https://mgdm.net/weblog/postgresql-in-a-nix-shell/

PostgreSQL installs properly in the shell (it's not installed on the main system at all), and I can start the server:

[nix-shell:~/Prog/Rust/ibis]$ pg_ctl -D .tmp/mydb -l logfile -o "--unix_socket_directories='$PWD'" start waiting for server to start.... done server started 

But then if I try to create a database it gives me an error about connection on server socket. I tried two ways and they give the same error:

[nix-shell:~/Prog/Rust/ibis]$ createdb mydb createdb: error: connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: No such file or directory Is the server running locally and accepting connections on that socket? 

and

[nix-shell:~/Prog/Rust/ibis]$ psql -c "CREATE USER ibis WITH PASSWORD 'censored' SUPERUSER;" -U postgres psql: error: connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: No such file or directory Is the server running locally and accepting connections on that socket? 

I have created a /run/postgresql/ folder within the project folder. I used chmod to give full permissions to all.

What am I not understanding here? I can start and stop the server, and the folder exists within the project folders.

1
  • In postgresql.conf per Connection settings is port set to something other then 5432 and what is listen_addresses set to. Add answers as text update to question text. Commented Oct 22 at 19:19

1 Answer 1

1

Well, if you created the Unix socket in $PWD, you cannot expect it to be in the location configured by postgresql.conf or the default location.

Try

createdb --host=$PWD mydb 
Sign up to request clarification or add additional context in comments.

2 Comments

> Your are just horsing around and experimenting, right? Not just messing around, but I've never used nix-shell before.
No problem with that, I was just curious.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.