PostgreSQL: uuid_generate fails
Dec 18, 2022 - by kurinchilamp / / Post Comment
i) If you are using pgadmin or any other psql client, make sure that the path to psql bin directory is correctly set under the client's preference
In pgAdmin4, it is File > Preference > Path > Binary Path
ii) Execute the below command if the extension is available but is not installed
db=# > \c <DATABASE>
db=# > CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
Continue Reading
PostgreSQL: How to drop a schema and all the tables inside it before restoring database?
Dec 14, 2022 - by kurinchilamp / / Post Comment
When we come across scenarios whereby we have to drop all the tables in a database before a restore, the following commands come in handy.
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO public;
To manually drop all tables in a database we
select 'DROP TABLE "' || tablename || '" cascade;' from pg_tables;
To check if a table exist and then to drop it if it does
select 'DROP TABLE IF EXISTS "' || tablename || '" cascade;' from pg_tables;
Continue Reading