HiveBrain v1.2.0
Get Started
← Back to all entries
principlesqlMinor

Postgres, benefit of named schema vs public schema?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresbenefitpublicnamedschema

Problem

I am new to Postgres and I am trying to understand how schemas fit into everything and what is the benefit of a non-'public' schema. For example, does it provide security, access control benefits or something else?

The setup I am working with is one where postgres owns the database and tables, but grants permissions to another user to select, insert, update, and delete. Would creating the tables in the 'public' schema vs 'myotherschema' make much of a difference?

Solution

what is the benefit of a non-'public' schema.

A schema provides a standardized level of logical organization. If you've never used them, it's like asking what's the value of directories. You don't technically need to have them, but you can use them to

  • Organize & Componentize



  • Control access



  • Reduce namespace-collisions



Also worth mentioning, the query planner can plan across schema boundaries. In the same sense that tools that operate on files can work across directories.


Perhaps more to the point of the Question you could explain that there is nothing special about the schema named public, just an arbitrarily chosen name for the default schema. – Basil Bourque 1 min ago

^ Valid point too. If you don't use your own customized schema, you're still using schema. It's just named public and placed in your search_path by default.

Context

StackExchange Database Administrators Q#188861, answer score: 8

Revisions (0)

No revisions yet.