Data directory is not empty! in postgres
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:
- Remove the existing data directory associated with Postgres:
[root@localhost bin]# rm -rf ~postgres/12
- 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.
← PostgreSQL Blog