Overview:
- A database in PostgreSQL is a container for schemas that contain several namespaces and tables underneath.
- PostgreSQL databases map to the catalogs as defined by the SQL standards.
- Database creation and removal operations are not frequent operations when compared to insert, update and deletion of data.
- The removal operation of a database involves removal of the underlying schemas, namespaces and tables. Hence care must be taken to ensure necessary backups have been made prior to removal of a database.
Example:
# ----- Example Python program that removes a PostgreSQL database ----- # Connect to PostgreSQL DBMS # Obtain a database Cursor # Create a database in PostgreSQL database # SQL statement for querying the list of databases # Execute the query statement # Retrieve all the rows from the cursor print("---List of databases before removing one:---"); # Remove database statement cur_ob.execute(sqlRemDb); # Remove the PostgreSQL database # Retrieve all the rows from the cursor print("---List of databases after removing one:---"); for row in rows: |
Output:
---List of databases before removing one:--- postgres selvamvinod test socialmedia mytestdatabase ---List of databases after removing one:--- postgres selvamvinod test socialmedia |