Skip to content

Instantly share code, notes, and snippets.

CREATE USER [database owner name] WITH CREATEROLE ENCRYTPED PASSWORD '[database owner's password]';
CREATE DATABASE [database name] OWNER [database owner name];
-- connect to [database name]
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON DATABASE [database name] FROM PUBLIC;
REVOKE ALL ON ALL TABLES IN SCHEMA public FROM PUBLIC;
-- log in as [database owner name] to [database name] db
CREATE SCHEMA [schema name];
@randypitcherii
randypitcherii / hashmap_zero_to_snowflake.sql
Last active November 16, 2022 11:31
SQL commands for Hashmap's slightly-modified Zero to Snowflake demonstrations. Find the original, official SQL from Snowflake at https://bit.ly/2JJZl3J
// This SQL file is for the Hands On Lab Guide for the 30-day free Snowflake trial account
// The numbers below correspond to the sections of the Lab Guide in which SQL is to be run in a Snowflake worksheet
// Modules 1 and 2 of the Lab Guide have no SQL to be run
// See the lab guide here - https://s3.amazonaws.com/snowflake-workshop-lab/InpersonZTS_LabGuide.pdf
//=====================================
// MODULE 1
// Steps to Prepare Your Lab Environment
@grandiloquent
grandiloquent / create_database.sql
Last active September 21, 2021 14:26
PostgreSQL Scripts
-- Database: goprojects
-- DROP DATABASE goprojects;
CREATE DATABASE goprojects
WITH
OWNER = postgres
ENCODING = 'UTF8'
LC_COLLATE = 'Chinese (Simplified)_People''s Republic of China.936'
LC_CTYPE = 'Chinese (Simplified)_People''s Republic of China.936'
@guedressel
guedressel / postgres-privileges-cheat-sheet
Last active September 24, 2021 19:31
Boilerplate DCL statements handy for PostgreSQL databases
CREATE DATABASE test OWNER postgres;
# connect to db test and stay connected for rest of statements in this file.
\c test
# prevent unauthorized access
REVOKE ALL ON DATABASE test FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM PUBLIC;
# create "groups" (read: ROLES)
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active June 1, 2024 14:11
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'