Skip to content

rashidov9797/PostgreSQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 

Repository files navigation

🐘 PostgreSQL Maintenance Tool

A powerful shell script designed to manage and monitor PostgreSQL databases.
Includes 18 useful functions for database administration, monitoring, and optimization.


πŸ“₯ Installation

  1. Download the file:
   wget https://github.com/rashidov9797/PostgreSQL/archive/refs/tags/v3.tar.gz
   tar -xzf v3.0.0.tar.gz
   cd PostgreSQL-3.0.0
  1. Make it executable:
   chmod +x maintenance.sh
  1. Run the script:
   ./maintenance.sh

✨ Features

# Feature Description
1 πŸ”’ Version Info Display PostgreSQL version
2 πŸ“Š Schema List List all database schemas
3 πŸ”΄ Active Sessions Show active database sessions
4 πŸ”’ Lock List Display locked resources
5 πŸ’€ Dead Tuple List Show dead tuples awaiting cleanup
6 πŸ’Ύ Tablespace Info Tablespace information and usage
7 πŸ” Top 15 Queries Most executed queries (requires pg_stat_statements)
8 🧹 Vacuum Info (Basic) Basic vacuum process information
9 πŸ“ˆ Commit & Hit Ratio Database commit and cache hit ratios
10 πŸ”„ Replication Delay Replication lag information
11 πŸ“‹ Object Count by Schema Count of objects per schema
12 πŸ“Š Index Usage Statistics Index usage and performance stats
13 ⚠️ Unused Indexes Identify unused indexes
14 ⏱️ Long Running Queries Detect long-running queries
15 🧹 Vacuum Info (Detailed) Detailed vacuum information
16 πŸ”„ Switch Database/User Change database or user connection
17 🚨 Log Error/Fatal/Panic Count Count errors in PostgreSQL logs
18 πŸ“€ Export Reports (CSV/HTML) Export reports in CSV or HTML format
99 πŸšͺ Exit Exit the script

image

πŸš€ Usage

  1. At startup, enter your PostgreSQL username and database name
  2. Select an option by entering a number between 1 and 18
  3. Use 99 to exit the script
  4. Option 16 allows you to switch between databases and users without restarting

πŸ†• What's New in v3.0

  • βœ… Option 17: Log Error/Fatal/Panic Count
    Saves to /home/postgres/pg_errors_YYYYMMDD.log

  • βœ… Option 18: Export Reports (CSV/HTML)
    Saves reports under /home/postgres/

    • CSV: Multiple separate files
    • HTML: Single combined file ALL_REPORT_YYYYMMDD_HHMMSS.html

πŸ” Recommended: Configure .pgpass

To avoid password prompts, configure .pgpass for the OS user running the script (e.g., postgres).

# Create .pgpass file
touch /home/postgres/.pgpass

# Add your credentials (format: hostname:port:database:username:password)
echo "localhost:5432:*:postgres:your_password" >> /home/postgres/.pgpass

# Set correct permissions
chmod 600 /home/postgres/.pgpass

Format:

hostname:port:database:username:password

Example:

localhost:5432:*:postgres:mypassword

πŸ‘€ Author

Azamat
GitHub: @rashidov9797


⭐ Support

If you find this tool helpful, please give it a star on GitHub!

About

PostgreSQL shell scripts

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages