Mak
Mak

Reputation: 139

How to import schema .sql file to a Postgresql database?

I am trying to import my schema.sql file of old DB to newly created Db in postgresql.

Could you please let me know the steps i need to follow to do this.

Env : linux centos 7 DB : postgresql 9.3 I have copied schema.sql file in directory /var/lib/pgsql/9.4/data/.

Regards.

Upvotes: 5

Views: 22263

Answers (2)

Lohit Gupta
Lohit Gupta

Reputation: 1081

you can directly execute the sql file using psql to create the schema in your new db:

psql -f schemadump.sql -p port -U username dbname

Upvotes: 13

atdima
atdima

Reputation: 137

Try

cat old_db_dump.sql | psql -U db_user_name -d new_db_name

Upvotes: 3

Related Questions