Last active
January 14, 2020 06:15
-
-
Save Checksum/00c140cbfb2a16080032061e515d831c to your computer and use it in GitHub Desktop.
PostgreSQL handy queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Get size of database | |
SELECT pg_size_pretty(pg_database_size('database-name')); | |
-- Set the current session as read only | |
SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY; | |
-- Locks | |
-- https://www.postgresql.org/docs/10/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS | |
SELECT pg_try_advisory_lock(123123213123) as lockObtained; | |
SELECT pg_try_advisory_unlock(123123213123); | |
-- Anonymous functions to verify migrations | |
do language plpgsql $$ | |
begin | |
if (select count(*) from table_name) > 0 then | |
raise exception 'Invalid count in table_name'; | |
end if; | |
end; | |
$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment