Presentation is loading. Please wait.

Presentation is loading. Please wait.

Power Selena Deckelmann psql End Point Corporation.

Similar presentations


Presentation on theme: "Power Selena Deckelmann psql End Point Corporation."— Presentation transcript:

1 Power Selena Deckelmann psql End Point Corporation

2 Thanks, Greg Sabino Mullane :)

3

4 Nobody’s Perfect VERSION BATCH LOOPS

5 Connecting psql –h yow –p 5432 –d cats –U alanis

6 Connecting Command LineEnvironment VariableExamples -h PGHOST / PGHOSTADDR yow.ca | /tmp/pg.5432 leading slash -dPGDATABASE(user)first arg

7 Connecting

8 ##host:port:database:username:password *:5432:*:bucardo:ZippityDoDah *:*:bucardo:bucardo:GoatInTheBox -W.pgpass

9 Connecting [ironic] host=yow dbname=herdocats user=alanis password: littl3p1ll pg_service.conf

10 Connecting psql “service=ironic” psql –d “service=ironic” psql “dbname=herdocats port=5432”

11 Connecting Use pg_service.conf Consistent ordering Avoid shortcuts

12 HELP! man psql psql -- help \? \h \h ALTER TABLE foo INT

13 Tab Completion tab-complete.creadlinecatalogs: pg_* => UPDATE table SET

14 Tab Completion

15 Backslash => \d => \dt => \df => \d => \dg \du \dr? => \o

16 Prompt PROMPT1 PROMPT2 PROMPT3 %/%R%# postgres=#

17 Weak! %/%R%#

18 \set PROMPT1 '%n@%m:%>|%/%R%#%x ' alanis@yow:5432|ironic=> alanis@yow:5432|ironic=> SELECT

19 %`date`%:name:%~ %

20 %[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# alanis@yow:5432|ironic=>

21 Variables

22 \set PROMPT2 :PROMPT1

23 readline ^e[a:"explain analyze" ctrl-r set –o vi (editline).inputrc

24 .psqlrc pslqrc

25 AUTOCOMMIT trick alanis@yow:5432|ironic=> begin; BEGIN alanis@yow:5432|ironic=>* delete from noise where id = 123; DELETE 1 alanis@yow:5432|ironic=>* rollback; ROLLBACK alanis@yow:5432|ironic=>

26 AUTOCOMMIT trick alanis@yow:5432|ironic=> \set AUTOCOMMIT off alanis@yow:5432|ironic=> delete from noise where id = 123; DELETE 1 alanis@yow:5432|ironic=>* alanis@yow:5432|ironic=>* rollback; ROLLBACK

27 AUTOCOMMIT trick alanis@yow:5432|ironic=> begin; BEGIN alanis@yow:5432|ironic=>* delete from noise where id = 123; DELETE 1 alanis@yow:5432|ironic=>* delete frm noise where id = 345; ERROR: syntax error at or near "frm" LINE 1: delete frm noise where id = 145; ^ alanis@yow:5432|ironic=>! select 123; ERROR: current transaction is aborted

28 AUTOCOMMIT trick alanis@yow:5432|ironic=> \set ON_ERROR_ROLLBACK on alanis@yow:5432|ironic=> begin; BEGIN alanis@yow:5432|ironic=>* delete frm noise where id = 123; ERROR: syntax error at or near "frm" alanis@yow:5432|ironic=>*

29 AUTOCOMMIT trick alanis@yow:5432|ironic=> \set AUTOCOMMIT off alanis@yow:5432|ironic=> \set ON_ERROR_STOP on alanis@yow:5432|ironic=> select 123; 123 alanis@yow:5432|ironic=> * !!!

30 AUTOCOMMIT trick alanis@yow:5432|ironic=> select 123; 123 alanis@yow:5432|ironic=> ***** :) \set PROMPT1 '%n@%m:%/|%>%R%#%x ' '%n@%m:%/|%>%R%#%x%x%x%x%x'

31 AUTOCOMMIT trick alanis@yow:5432|ironic=> select 123; 123 alanis@yow:5432|ironic=> ***** :) \set PROMPT1 '%n@%m:%/|%>%R%#%x ' '%n@%m:%/|%>%R%#%x%x%x%x%x'

32 AUTOCOMMIT trick check_postgres_txn_idle --warning='5 seconds' --critical='60 seconds' :) http://bucardo.org/check_postgres/

33 PAGING \pset pager always export PAGER=lessexport LESS='-SFX'

34 Peeking inside \d-E information_schema

35 Quick modify => \t => select 'DROP TABLE '||quote_ident(relname)||';' FROM pg_class WHERE relname ~ '^testing_' AND relkind='r'; DROP TABLE testing_alpha; DROP TABLE "testing_one two three"; => \o drop_testing_tables.sql => \g => \o => \! less drop_testing_tables.sql => \set ON_ERROR_STOP on => BEGIN; => \i drop_testing_tables.sql

36 Batch and cron Flags: -A -X -q -t

37 -AX –qt Batch and cron

38 -AX –qt Batch and cron PSQL='psql -AX -qt' */5 * * * * $PSQL -d bucardo -c "SELECT bucardo_purge_ delta('5 minutes'::interval)"

39 -AX –qt Batch and cron $ psql –AX –qt –c 'SELECT pg_sleep(0)' | wc 1 0 1 ?!?

40 -AX –qt Batch and cron :) PSQL='psql -AX -qt' */5 * * * * $PSQL -d bucardo -c "SELECT bucardo_purge_ delta('5 minutes'::interval)" | perl –pe 's/^\n// if $.<2'

41 -AX –qt Batch and cron Yikes */5 * * * * (echo "COPY ark FROM STDIN;" && $PSQL –d prod -c "COPY (SELECT * FROM ark_audit) TO STDOUT" && echo "\\.") | $PSQL -d postgres -f -

42 The Future \c & ref seq \x09 kid \dfS TABLE \ef \timing \d+ \dT \l+ You -w7.4 help rap

43 Power Twitter: psql postgres_totd


Download ppt "Power Selena Deckelmann psql End Point Corporation."

Similar presentations


Ads by Google