You must specify the database to use on connect; if you want to use psql for your script, you can use "\c name_database" user_name=# CREATE DATABASE testdatabase; user_name=# \c testdatabase At this point you might see the following output You are now connected to database "testdatabase" as user "user_name". testdatabase=#mydb