Thursday, September 27, 2018

Drop database and then restore (Postgresql 10.4.0):

1. su as postgres

2. run psql at command prompt

3. First, find the activities that are taken place against the target database, you can query the pg_stat_activity view with the following query:

SELECT
 *
FROM
 pg_stat_activity
WHERE
 datname = 'target_database';


4. Second, terminate the active connections by issuing the following query:

SELECT
 pg_terminate_backend (pg_stat_activity.pid)
FROM
 pg_stat_activity
WHERE
 pg_stat_activity.datname = 'target_database';


5. Third, execute the DROP DATABASE statement:

DROP DATABASE target_database;

6. Create database:

CREATE DATABASE target_database;

7. Copy file from host to docker container:

docker cp src/. mycontainer:/target

8. Go into docker container and restore database:

docker container exec -it mycontainer bash
su postgres
psql target_database < infile

That's all folks!

No comments:

Post a Comment

Install MySQL 8.0 on Centos 7

Steps to install MySQL 8.0 Community Edition in Centos 7 1. Enable MySQL 8.0 Repository sudo yum localinstall https://dev.mysql.com...