Operating system: Ubuntu
Run the following command to create a database named mydb
createdb mydb
Get an error: PSQL: fatal: role “Terry” does not exist. Terry is my machine name. There is no role named Terry in the PostgreSQL database, so this error will be reported. Just add the – U parameter to specify an existing role, so I change the above command to:
createdb mydb -U postgres
Get another error: PSQL: fatal: Peer authentication failed for user “Postgres”. The solution is as follows:
1. Run the following command to edit PG_ Hba.conf file
sudo gedit /etc/postgresql/9.1/main/pg_hba.conf
2. Will
# Database administrative login by Unix domain socket local all postgres peer
Change to
# Database administrative login by Unix domain socket local all postgres trust
3. After saving, execute the following command to reload the configuration file:
sudo /etc/init.d/postgresql reload
Then execute CREATEDB mydb1 – u Postgres, and the mydb1 database has been successfully created