-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgres.alias
executable file
·56 lines (40 loc) · 1.92 KB
/
Postgres.alias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# PostgreSQL Aliases
# Add these to your ~/.bashrc or ~/.bash_aliases file
# Basic psql connection with default database
alias psql='psql -U postgres'
# List all databases
alias psl='psql -l'
# Connect to a specific database
# Usage: psdb database_name
alias psdb='psql -U postgres -d'
# Backup database
# Usage: pgbackup database_name
alias pgbackup='pg_dump -U postgres -F c -b -v -f'
# Restore database from backup
# Usage: pgrestore backup_file database_name
alias pgrestore='pg_restore -U postgres -d'
# Monitor PostgreSQL processes
alias pgps='psql -U postgres -c "SELECT pid, usename, client_addr, state, query_start, query FROM pg_stat_activity;"'
# Show database sizes
alias pgsize='psql -U postgres -c "SELECT pg_database.datname, pg_size_pretty(pg_database_size(pg_database.datname)) AS size FROM pg_database ORDER BY pg_database_size(pg_database.datname) DESC;"'
# Show table sizes in current database
alias pgtsize='psql -U postgres -c "SELECT schemaname, relname, pg_size_pretty(pg_total_relation_size(relid)) AS total_size FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC;"'
# Kill all connections to a database
# Usage: pgkill database_name
alias pgkill='psql -U postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='\''$1'\'' AND pid <> pg_backend_pid();"'
# Create a new database
# Usage: pgcreate database_name
alias pgcreate='createdb -U postgres'
# Drop a database
# Usage: pgdrop database_name
alias pgdrop='dropdb -U postgres'
# Start PostgreSQL server (adjust path as needed)
alias pgstart='sudo service postgresql start'
# Stop PostgreSQL server
alias pgstop='sudo service postgresql stop'
# Restart PostgreSQL server
alias pgrestart='sudo service postgresql restart'
# Show PostgreSQL server status
alias pgstatus='sudo service postgresql status'
# Tail PostgreSQL logs (adjust path as needed)
alias pglog='sudo tail -f /var/log/postgresql/postgresql-*.log'