This file contains hidden or 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
EXEC sp_WhoIsActive | |
@filter = '', | |
@filter_type = 'session', | |
@not_filter = '', | |
@not_filter_type = 'session', | |
@show_own_spid = 0, | |
@show_system_spids = 0, | |
@show_sleeping_spids = 1, | |
@get_full_inner_text = 0, | |
@get_plans = 0, |
This file contains hidden or 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
DO | |
$$ | |
BEGIN | |
EXECUTE format('CREATE TABLE %I AS SELECT * FROM backup', 'backup_' || to_char(CURRENT_DATE,'yyyy-mm-dd')); | |
END; | |
$$ LANGUAGE plpgsql; | |
CREATE OR REPLACE FUNCTION fn_hello(v_table text) | |
returns void |
This file contains hidden or 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
--for a cross db query on the same host | |
--no hostname or password is needed. | |
--the following script adds the extension, | |
-- creates a server, maps the postgres user, | |
-- and imports the foreign db into a new schema | |
BEGIN; | |
CREATE EXTENSION IF NOT EXISTS postgres_fdw; | |
DROP SERVER IF EXISTS fdw_server CASCADE; |
This file contains hidden or 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
--1. Create Tables: | |
Create table Genres ( | |
Id int primary key | |
, genre varchar(50)) | |
-- I would recommend making all your ids IDENTITY columns so those ids are generated automatically. I'm making the comment here but this would be true across the board. | |
Create table Movies ( | |
id int primary key |
This file contains hidden or 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
pg_config --version|grep -oP "(?<=PostgreSQL ).*" |
This file contains hidden or 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
myaliases = { | |
# 'grep': 'grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn}', | |
# one char shortcuts | |
'h': 'history show all | less', | |
'c': 'clear', | |
# ls shortcuts | |
'l': 'ls -F', | |
'la': 'ls -lAfh', | |
'll': 'ls -lFh', | |
'ldot': 'ls -ld .*', |
This file contains hidden or 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
CREATE INDEX index_notifications_gin_subscriber ON notifications USING gin ((params ->> 'subscriber') gin_trgm_ops) WHERE params -> 'subscriber':: text IS NOT NULL; |
This file contains hidden or 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
SELECT | |
c.relname, | |
indexname, | |
c.reltuples AS num_rows, | |
pg_size_pretty(pg_relation_size(quote_ident(c.relname)::text)) AS table_size, | |
pg_size_pretty(pg_relation_size(quote_ident(indexrelname)::text)) AS index_size, | |
CASE WHEN indisunique THEN 'Y' | |
ELSE 'N' | |
END AS UNIQUE, | |
idx_scan AS number_of_scans, |
This file contains hidden or 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
1. Create tables to hold data for your movie collection. | |
Create table Movies (id int identity primary key, | |
Title varchar (100), | |
Director varchar (100), | |
Runtime smallint, | |
Genre_id int, | |
Release_Year year); | |
Create table Genre (id int identity primary key, |
This file contains hidden or 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
#To display the largest folders/files including the sub-directories, run: | |
du -Sh | sort -rh | head -5 | |
#du command: Estimate file space usage. | |
#-h : Print sizes in human-readable format (e.g., 10MB). | |
#-S : Do not include the size of subdirectories. | |
#-s : Display only a total for each argument. | |
#sort command : sort lines of text files. | |
#-r : Reverse the result of comparisons. |