Skip to main content

A simple tool to reduce PostgreSQL dump size by nullifying large bytea/text columns.

Project description

pgslim 🐘

A simple Python CLI tool to reduce the size of a PostgreSQL dump by nullifying large bytea or text columns.

This is particularly useful when you've accidentally stored large files (like images, PDFs, or JSON responses) in your database and want to create a smaller dump for local development or staging.

Installation

You can install pgslim directly from PyPI (once uploaded):

pip install pgslim

Or from source:

git clone https://github.com/nguyenhuy158/pgslim
cd pgslim
pip install .

Usage

You can use pgslim in either Interactive Mode or Command-Line Mode.

Interactive Mode (Recommended)

Simply run the tool with no arguments to start an interactive wizard. It will scan your current directory for .sql files, fast-scan the selected file for tables and columns, and provide searchable dropdown menus to make your selection.

pgslim

Alternatively, you can provide a directory path to scan for .sql files:

pgslim /path/to/dumps

Command-Line Mode

For automation or quick usage, provide the input SQL file, the table name, and the column you want to nullify directly as positional arguments or named flags.

# Using positional arguments
pgslim dump_old.sql my_table large_column

# Using named flags
pgslim -i dump_old.sql -t my_table -c large_column -v

This will create a new file named dump_old_slim.sql (unless you specify a custom output with -o).

Arguments

Positional / Named Flag Description
input / -i, --input Input SQL dump file (plain text format)
table / -t, --table Name of the table (e.g., users)
column / -c, --column Name of the column to nullify (e.g., attachment)
Optional Flag Description
-o, --output Output SQL dump file (defaults to <input>_slim.sql)
-v, --verbose Enable verbose output to see detailed progress

How it works

The tool parses the COPY blocks in a PostgreSQL plain-text dump. It identifies the target table and the index of the specified column. For every row in that COPY block, it replaces the column value with \N (PostgreSQL's representation of NULL).

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pgslim-0.2.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pgslim-0.2.0-py2.py3-none-any.whl (5.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pgslim-0.2.0.tar.gz.

File metadata

  • Download URL: pgslim-0.2.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for pgslim-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ea0b8adec3b353a11be8bb5f3756a89f65e984c58a61c75048bb33cb5e50e961
MD5 29215cf81f9bff5d2337a5e9d0351891
BLAKE2b-256 eac2e903c204d493349b19be78c3d46356b07f23f5950e9324f53c53cf4ff5f0

See more details on using hashes here.

File details

Details for the file pgslim-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pgslim-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for pgslim-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 97952e8ecbc2948c6f6bdcf2ec7f249b5a4ad1659039143b279f97680d036fd8
MD5 fe05649178539c9d976473e7fd138c6d
BLAKE2b-256 dccd4a0d2aee19a92712d5279831cb0e967fbc9db85bc2bb08224d133e94e9a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page