Clone a database with an existing local one
Connect to the database with a user with proper right and make sure that the sourcedb does not have opened connection.
CREATE DATABASE <targetdb> WITH TEMPLATE <sourcedb>;
Database dump
pg_dump -h 127.0.0.1 --verbose -U <postgres_user> -p <port> -f <dump_name> -Fd <database_to_dump>
Database restore
pg_restore --verbose -U <postgres_user> -p <port> -d <destination_db> -Fd <backup_folder>
Get table fields
SELECT *
FROM information_schema.columns
WHERE table_name = '<table_name>';
Try catch block
do
$$
begin
-- normal execution
perform 1;
exception when others then
-- fallback execution
perform 2;
end;
$$;
0 Comments