Is it possible to run PostgreSQL within IDX for development?

The project I am working on uses PostgreSQL database and I am wondering if I can install PostgreSQL server on IDX for local development?

Found a solution:

  1. add pkgs.postgresql_14 to your list of packages and rebuild your environment. All postgres server commands are available.
  2. init and start the db server like normal
# create pgdata folder
mkdir ~/pgdata

# initialize db 
initdb --pgdata=~/pgdata --username=postgres

# try to connect
psql -U postgres
1 Like

Instead of creating initdb etc. easier way is to add services.postgres

And add line below packages end like

services.postgres = {
  enable = true;   
  enableTcp = true;
};

Tried the steps here,
But get the following error when trying to start the instance: FATAL: could not create lock file “/run/postgresql/.s.PGSQL.5432.lock”: No such file or directory
EDIT: False alarm. Worked after creating the dir /run/postgresql

We do have an official Postgres template that you could use (or look a the dev.nix file for to reproduce on a different workspace): https://idx.google.com/new/postgres

1 Like