Logo ← PostgreSQL Blog

Data directory is not empty! in postgres

Problem: When trying to initialize a new Postgres database using the command /usr/pgsql-12/bin/postgresql-12-setup initdb, an error message…

Data directory is not empty! in postgres

Problem: When trying to initialize a new Postgres database using the command /usr/pgsql-12/bin/postgresql-12-setup initdb, an error message is encountered indicating that the data directory is not empty.

[root@localhost bin]# /usr/pgsql-12/bin/postgresql-12-setup initdb
Data directory is not empty!

Solution:

To resolve this issue, you can follow these steps:

  1. Remove the existing data directory associated with Postgres:
[root@localhost bin]# rm -rf ~postgres/12
  1. Re-run the initialization command to set up the database:
[root@localhost bin]# /usr/pgsql-12/bin/postgresql-12-setup initdb
Initializing database … OK

By following these steps, you should be able to successfully initialize a new Postgres database without encountering the “Data directory is not empty!” error.