Postgres Database

Creator
Creator
Seonglae ChoSeonglae Cho
Created
Created
2020 Mar 1 11:24
Editor
Edited
Edited
2022 Aug 10 17:23
Refs
Refs
REVOKE CONNECT ON DATABASE thedb FROM public; DROP DATABASE mms; CREATE DATABASE mms; OWNER = role_name
 
CREATE DATABASE db_name OWNER = role_name TEMPLATE = template ENCODING = encoding LC_COLLATE = collate LC_CTYPE = ctype TABLESPACE = tablespace_name CONNECTION LIMIT = max_concurrent_connection
 
 

copy

  • connection 있을때 안되서
    pg_dump
    이용이 편함
SELECT pid, usename, client_addr FROM pg_stat_activity WHERE datname =''; SELECT pg_terminate_backend (pid) FROM pg_stat_activity WHERE datname = ''; CREATE DATABASE mms_test WITH TEMPLATE mms;
 

Drop

connect to that db
SELECT pid, pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = current_database() AND pid <> pg_backend_pid();
 
 
Postgresql - unable to drop database because of some auto connections to DB
In my case, I am using AWS Redshift (based on Postgres). And it appears there are no other connections to the DB, but I am getting this same error. ERROR: database "XYZ" is being accessed by other users In my case, it seems the database cluster is still doing some processing on the database, and while there are no other external/user connections, the database is still internally in use.
Postgresql - unable to drop database because of some auto connections to DB
PostgreSQL Copy Database Made Easy
Summary: in this tutorial, you will learn how to copy a PostgreSQL database on the same server or from a server to another. Sometimes, you want to copy a PostgreSQL database within a database server for testing purposes. PostgreSQL makes it easy to do it via the CREATE DATABASE statement as follows: This statement copies the sourcedb to the targetdb.
PostgreSQL Copy Database Made Easy
PostgreSQL CREATE DATABASE with Example
The syntax to create a database in PostgreSQL is CREATE DATABASE databasename
PostgreSQL CREATE DATABASE with Example
PostgreSQL Copy Database Made Easy
Summary: in this tutorial, you will learn how to copy a PostgreSQL database on the same server or from a server to another. Sometimes, you want to copy a PostgreSQL database within a database server for testing purposes. PostgreSQL makes it easy to do it via the CREATE DATABASE statement as follows: This statement copies the sourcedb to the targetdb.
PostgreSQL Copy Database Made Easy
 
 

Recommendations