Reputation: 7144
I hope someone can help me to learn about Postgres schema and databases.
I have Postgres database called db1 and it has table calls table1. all these objects are in default schema called public.
Then I created another database called db2 and created another table with same name table1.
I didn't got any error but both tables are in same schema called public.
I created indexes for both of these tables and they both refer the table as public.table1.
I wonder a setup like this will give issue or not? If yes, then should I create different schemas for each database if I'm going to use same table names in all databases?
Upvotes: 0
Views: 1755
Reputation: 37472
In Postgres a database is the highest level "container". Then schemas follow. There can be schemas with the same name in different databases (but not in the same database). The other databases won't "see" them. So there is no problem in your setup.
Upvotes: 3
Reputation: 3110
Can we have two Postgres databases in same schema?
The answer is no. The relevant PostgreSQL documentation shows the hierarchy:
database.schema.table
This diagram (taken from this answer) is useful to visualise the relationship:
Upvotes: 3