Download the PHP package weslinkde/laravel-postgres-tools without Composer
On this page you can find all versions of the php package weslinkde/laravel-postgres-tools. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download weslinkde/laravel-postgres-tools
More information about weslinkde/laravel-postgres-tools
Files in weslinkde/laravel-postgres-tools
Package laravel-postgres-tools
Short Description Some handy helper function for PostgresSQL Databases
License MIT
Homepage https://github.com/weslinkde/laravel-postgres-tools
Informations about the package laravel-postgres-tools
Laravel Postgres Tools
A Laravel package for PostgreSQL database management, optimized for large databases (16GB+). Create snapshots, restore backups, and manage databases with native PostgreSQL tools for maximum performance.
Features
- Database Snapshots: Create and restore database dumps using native
pg_dumpandpg_restore - Large Database Support: Optimized for databases 16GB+ with streaming and parallel processing
- Database Management: Create, drop, and clone PostgreSQL databases
- Flexible Storage: Store snapshots on any Laravel filesystem disk (local, S3, etc.)
- Table Filtering: Include or exclude specific tables from snapshots
- Parallel Restore: Configure parallel jobs for faster restoration
- Fails Loudly: Every PostgreSQL command is checked; a failed restore aborts with the original
pg_restoreerror and a non-zero exit code
Requirements
- PHP 8.2+
- Laravel 11, 12, or 13
- PostgreSQL database
- PostgreSQL CLI tools (
pg_dump,pg_restore,createdb,dropdb), at least as new as the server the snapshots come from
Installation
Install the package via composer:
Publish the config file:
Configuration
Don't forget to configure your snapshots disk in config/filesystems.php:
Usage
Create a Snapshot
Load a Snapshot
Delete a Snapshot
Database Management
Performance Tuning
Compression Level
The -Z flag controls compression (0-9). Higher = smaller files but slower:
| Level | Speed | Use Case |
|---|---|---|
-Z 1 |
Fastest | Very large databases (50GB+) |
-Z 3 |
Balanced | Recommended default |
-Z 9 |
Slowest | Maximum compression needed |
Parallel Restore
Snapshots are written with pg_dump --file, so the archive records data offsets and pg_restore --jobs can genuinely restore in parallel. Configure parallel jobs based on database size:
| Database Size | Recommended Jobs |
|---|---|
| < 1GB | 1-2 |
| 1-10GB | 4 |
| 10GB+ | CPU cores - 2 |
Cloud Storage
When using remote storage (S3, etc.), snapshots are automatically streamed to a local temp directory during restore to avoid memory issues.
Client Version Mismatches
pg_restore can only read archives written by a pg_dump of the same major version or older. A PostgreSQL 14 client reading a dump from a PostgreSQL 16 server fails with:
weslink:snapshot:load verifies the archive with pg_restore --list before it drops a single table, so a mismatch aborts while the target database is still intact:
Instead of relying on whatever pg_restore happens to be first on PATH, pin the client explicitly:
This path is used for pg_dump, pg_restore, psql, createdb and dropdb alike.
Error Handling
Every command exits with a non-zero status when it fails, so scripts and CI can detect problems:
| Situation | Behaviour |
|---|---|
| Archive unreadable by the local client | Aborts before dropping anything, exit code 1 |
pg_restore fails during the restore |
RestoreFailed with the full pg_restore stderr, exit code 1 |
createdb / dropdb fails |
DatabaseOperationFailed with the client stderr, exit code 1 |
psql cannot reach the server |
Throws instead of reporting "database does not exist" |
| Snapshot streamed incompletely from a remote disk | Aborts before dropping anything, exit code 1 |
| Snapshot name not found | Warning, exit code 1 |
Schema/data dump or VACUUM ANALYZE fails |
Error with the client stderr, exit code 1 |
| Listing an empty set of snapshots or databases | Warning, exit code 0 — an empty result is not a failure |
The exceptions live in Weslinkde\PostgresTools\Exceptions and all extend ProcessFailed, which carries the exit code, stdout and stderr of the failed command in its message.
Security
All PostgreSQL commands are built as argument arrays and executed without a shell, so table names, hosts and database names coming from configuration or command line options cannot be interpreted as shell syntax. Database names are handed to psql as variables (:'dbname') rather than interpolated into SQL. Passwords are passed via PGPASSWORD / PGPASSFILE, never on the command line.
Events
The package dispatches events during snapshot operations:
| Event | Description |
|---|---|
Weslinkde\PostgresTools\Events\CreatingSnapshot |
Before snapshot creation |
Weslinkde\PostgresTools\Events\CreatedSnapshot |
After snapshot creation |
Weslinkde\PostgresTools\Events\LoadingSnapshot |
Before snapshot loading |
Weslinkde\PostgresTools\Events\LoadedSnapshot |
After snapshot loading |
Weslinkde\PostgresTools\Events\DeletingSnapshot |
Before snapshot deletion |
Weslinkde\PostgresTools\Events\DeletedSnapshot |
After snapshot deletion |
Example Event Listener
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Dominik Lenz
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-postgres-tools with dependencies
illuminate/contracts Version ^11.0 || ^12.0 || ^13.0
illuminate/filesystem Version ^11.0 || ^12.0 || ^13.0
illuminate/support Version ^11.0 || ^12.0 || ^13.0
laravel/prompts Version ^0.1 || ^0.2 || ^0.3
symfony/process Version ^7.0 || ^8.0