PHPackages                             weslinkde/laravel-postgres-tools - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. weslinkde/laravel-postgres-tools

ActiveLibrary[Database &amp; ORM](/categories/database)

weslinkde/laravel-postgres-tools
================================

Some handy helper function for PostgresSQL Databases

v1.3.1(2mo ago)35.4k↓50%1[1 PRs](https://github.com/weslinkde/laravel-postgres-tools/pulls)MITPHPPHP ^8.2CI passing

Since Jan 4Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/weslinkde/laravel-postgres-tools)[ Packagist](https://packagist.org/packages/weslinkde/laravel-postgres-tools)[ Docs](https://github.com/weslinkde/laravel-postgres-tools)[ GitHub Sponsors](https://github.com/Weslinkde)[ RSS](/packages/weslinkde-laravel-postgres-tools/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (36)Versions (21)Used By (0)

Laravel Postgres Tools
======================

[](#laravel-postgres-tools)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8f58d732313f4cba4c00f8f2870f31cf70ff10a33816f2613ba7d81ddc3e6b4d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7765736c696e6b64652f6c61726176656c2d706f7374677265732d746f6f6c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/weslinkde/laravel-postgres-tools)[![GitHub Tests Action Status](https://github.com/weslinkde/laravel-postgres-tools/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/weslinkde/laravel-postgres-tools/actions/workflows/run-tests.yml)[![GitHub Code Style Action Status](https://github.com/weslinkde/laravel-postgres-tools/actions/workflows/fix-php-code-style-issues.yml/badge.svg?branch=master)](https://github.com/weslinkde/laravel-postgres-tools/actions/workflows/fix-php-code-style-issues.yml)[![Total Downloads](https://camo.githubusercontent.com/b2a8b894477d349d6668686a620b3d6c4d6f818f934ba11fc008e752b570346d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7765736c696e6b64652f6c61726176656c2d706f7374677265732d746f6f6c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/weslinkde/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
--------

[](#features)

- **Database Snapshots**: Create and restore database dumps using native `pg_dump` and `pg_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

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10, 11, or 12
- PostgreSQL database
- PostgreSQL CLI tools (`pg_dump`, `pg_restore`, `createdb`, `dropdb`)

Installation
------------

[](#installation)

Install the package via composer:

```
composer require weslinkde/laravel-postgres-tools
```

Publish the config file:

```
php artisan vendor:publish --tag="postgres-tools-config"
```

### Configuration

[](#configuration)

```
return [
    // Laravel filesystem disk for storing snapshots
    'disk' => 'snapshots',

    // Default database connection (must be pgsql driver)
    'default_connection' => 'pgsql',

    // Temporary directory for streaming from remote disks
    'temporary_directory_path' => storage_path('app/laravel-db-snapshots/temp'),

    // Include only these tables (null = all tables)
    'tables' => env('PG_INCLUDE_TABLES', null),

    // Exclude these tables (null = no exclusions)
    'exclude' => env('PG_EXCLUDE_TABLES', null),

    // pg_dump options
    'addExtraOption' => env('PG_DUMP_OPTIONS', '--no-owner --no-acl --no-privileges -Z 3 -Fc'),

    // Parallel restore jobs
    'jobs' => env('PG_RESTORE_JOBS', 4),
];
```

Don't forget to configure your snapshots disk in `config/filesystems.php`:

```
'disks' => [
    'snapshots' => [
        'driver' => 'local',
        'root' => storage_path('app/snapshots'),
    ],
],
```

Usage
-----

[](#usage)

### Create a Snapshot

[](#create-a-snapshot)

```
# With a custom name
php artisan weslink:snapshot:create my-backup

# Auto-generated name (timestamp)
php artisan weslink:snapshot:create

# Include only specific tables
php artisan weslink:snapshot:create --table=users --table=posts

# Exclude specific tables
php artisan weslink:snapshot:create --exclude=logs --exclude=cache

# Use a different connection
php artisan weslink:snapshot:create --connection=other_pgsql
```

### Load a Snapshot

[](#load-a-snapshot)

```
# Load a specific snapshot
php artisan weslink:snapshot:load my-backup

# Load to a different connection
php artisan weslink:snapshot:load my-backup --connection=other_pgsql

# Load the most recent snapshot
php artisan weslink:snapshot:load --latest

# Skip dropping existing tables
php artisan weslink:snapshot:load my-backup --drop-tables=0

# Skip confirmation prompt
php artisan weslink:snapshot:load my-backup --force
```

### Delete a Snapshot

[](#delete-a-snapshot)

```
php artisan weslink:snapshot:delete my-backup
```

### Database Management

[](#database-management)

```
# Create a new database
php artisan weslink:database:create new_database

# Drop a database (requires confirmation in production)
php artisan weslink:database:drop old_database

# Clone a database
php artisan weslink:database:clone source_db target_db
```

Performance Tuning
------------------

[](#performance-tuning)

### Compression Level

[](#compression-level)

The `-Z` flag controls compression (0-9). Higher = smaller files but slower:

LevelSpeedUse Case`-Z 1`FastestVery large databases (50GB+)`-Z 3`BalancedRecommended default`-Z 9`SlowestMaximum compression needed```
# In your .env file
PG_DUMP_OPTIONS="--no-owner --no-acl --no-privileges -Z 1 -Fc"
```

### Parallel Restore

[](#parallel-restore)

Configure parallel jobs based on database size:

Database SizeRecommended Jobs&lt; 1GB1-21-10GB410GB+CPU cores - 2```
# In your .env file
PG_RESTORE_JOBS=8
```

### Cloud Storage

[](#cloud-storage)

When using remote storage (S3, etc.), snapshots are automatically streamed to a local temp directory during restore to avoid memory issues.

Events
------

[](#events)

The package dispatches events during snapshot operations:

EventDescription`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

[](#example-event-listener)

```
use Weslinkde\PostgresTools\Events\CreatedSnapshot;

class NotifyBackupComplete
{
    public function handle(CreatedSnapshot $event): void
    {
        // $event->snapshot contains the Snapshot instance
        Log::info("Snapshot created: {$event->snapshot->name}");
    }
}
```

Testing
-------

[](#testing)

```
# Run all tests
composer test

# Run with coverage
composer test-coverage

# Run PHPStan analysis
composer analyse
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Dominik Lenz](https://github.com/Udaberrico)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance82

Actively maintained with recent releases

Popularity28

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~47 days

Recently: every ~22 days

Total

18

Last Release

67d ago

Major Versions

v0.5.5 → v1.0.02025-12-15

PHP version history (2 changes)v0.1.0PHP ^8.1

v1.0.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/27858387?v=4)[weslink](/maintainers/weslinkde)[@weslinkde](https://github.com/weslinkde)

---

Top Contributors

[![Udaberrico](https://avatars.githubusercontent.com/u/15997638?v=4)](https://github.com/Udaberrico "Udaberrico (31 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (15 commits)")[![azgooon](https://avatars.githubusercontent.com/u/26380378?v=4)](https://github.com/azgooon "azgooon (14 commits)")[![semantic-release-bot](https://avatars.githubusercontent.com/u/32174276?v=4)](https://github.com/semantic-release-bot "semantic-release-bot (3 commits)")[![christoferw](https://avatars.githubusercontent.com/u/298492?v=4)](https://github.com/christoferw "christoferw (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravelWeslinkdelaravel-postgres-tools

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/weslinkde-laravel-postgres-tools/health.svg)

```
[![Health](https://phpackages.com/badges/weslinkde-laravel-postgres-tools/health.svg)](https://phpackages.com/packages/weslinkde-laravel-postgres-tools)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M369](/packages/laravel-zero-framework)[laravel/installer

Laravel application installer.

83610.7M20](/packages/laravel-installer)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
