Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. Postgres
  2. ========
  3.  
  4. Command to display active connections to a PostgresDB: `SELECT * FROM pg_stat_activity;`
  5.  
  6. Connection to Redshift
  7. ----------------------
  8.  
  9. ```
  10. $ psql -h <ENDPOINT_NAME>.us-east-1.redshift.amazonaws.com -p 5439 -d <DB_NAME> -U <DB_USERNAME>
  11. password <TYPE_YOUR_PASSWORD_HERE>
  12. ```
  13.  
  14. ```
  15. \list or \l: list all databases
  16. \dt: list all tables in the current database
  17. \dn: list of schemas
  18. \dt <schema_name>.*: list tables in <schema_name>
  19. \d+ <schema_name>.<table_name>: describe a table in a schema
  20. SET search_path = <schema_name>;
  21. ```
  22.  
  23. To find all the columns with a name like query:
  24. ```
  25. select table_name, column_name
  26. from information_schema.columns
  27. where table_schema=<SCHEMA_NAME> and column_name like '%some%thing%';
  28. ```
  29.  
  30. To see output in VERTICAL form:
  31. ```
  32. \x # enable vertical output
  33. <your queries>
  34. \x # disable vertical output
  35. ```
  36.  
  37. MySQL
  38. =====
  39.  
  40. Connection
  41. ----------
  42.  
  43. ```
  44. $ mysql -h <HOST_IP> -P 3306 -u <DB_USERNAME> -p -A -D <DB_NAME>
  45. <TYPE_YOUR_PASSWORD_HERE>
  46. ```
  47.  
  48. ```
  49. show databases;
  50. use <DB_NAME>;
  51. <YOUR QUERY> \G # the output in VERTICAL form
  52. ```
  53.  
  54. Performing a dump
  55. -----------------
  56.  
  57. ```
  58. $ mysqldump -P 3306 -h <HOST_IP> -u <DB_USERNAME> -p <DB_PASSWORD> <TABLE_NAME> --where="columns='some_value'" > ~/tmp/foo.sql
  59. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement