PostgreSQL - So ändern Sie das Standardschema

PostgreSQL - So ändern Sie das Standardschema

"Public" ist das PostgreSQL-Standardschema. Ich muss es ändern, da ich neue Datenbankdaten in ein anderes neues Schema namens "new_public" migriert habe.
Bevor ich mit der Änderung beginne, muss ich das aktuelle PostgreSQL-Standardschema überprüfen ?

1) Befehl

SHOW search_path

2) Überprüfen Sie die postgresql.conf

#---------------------------------------------------------------------------
# CLIENT CONNECTION DEFAULTS
#---------------------------------------------------------------------------

# - Statement Behavior -

#search_path = '"$user",public'     # schema names
#default_tablespace = ''        # a tablespace name, '' uses
                    # the default
#check_function_bodies = on
#default_transaction_isolation = 'read committed'
#default_transaction_read_only = off

Hier zeige ich, wie man das Postgresql-Standardschema ändert.

SET search_path = new_schema

Der obige Befehl gilt jedoch nur für die aktuelle Sitzung. Das nächste Mal wird das Schema wieder in public geändert. Wenn wir dauerhaft wirksam werden möchten, müssen wir die Datei postgresql.conf wie folgt ändern.

#---------------------------------------------------------------------------
# CLIENT CONNECTION DEFAULTS
#---------------------------------------------------------------------------

# - Statement Behavior -

#search_path = '"$user",public'     # schema names
search_path = '"$user",new_schema'  # NEW SCHEMA HERE
#default_tablespace = ''        # a tablespace name, '' uses
                    # the default
#check_function_bodies = on
#default_transaction_isolation = 'read committed'
#default_transaction_read_only = off

Starten Sie danach einfach den PostgreSQL-Dienst neu. Erledigt.