0

I've cloned this Github repository PostgreSQL VM via Vagrant. Been trying to create a new schema test but it always ends up under postgres database. Considering the create database is named myapp, how can I create the test schema under myapp database?

I've been trying to add this script under the Vagrant-setup/bootstrap.sh.

cat << EOF | su - postgres -c psql myapp

create schema test;

EOF

David B
  • 3,269
  • 12
  • 48
  • 80
  • When connected to the database myapp you can't create a schema (or any other database object) in another database. If it happens that a database object ends up in the wrong database, you were connected to the wrong database. – Frank Heikens Jun 22 '22 at 17:39

1 Answers1

0

As a reference it may help to check your connection string in order to ensure you are connected to the right database. The official postgresql documentation is quite helpful here:

https://www.postgresql.org/docs/current/libpq-connect.html

This may help as well for understanding the format:

What is the format for the PostgreSQL connection string / URL?

Outside of that you will have to ensure permissions are set appropriately for the user to create schemas in the database and to configure the search_path for easy access to objects under the schema.

Poiuy
  • 331
  • 2
  • 6