PHPackages                             slam/psql-php - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. slam/psql-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

slam/psql-php
=============

PHP version of psql cli that comes with PostgreSQL

v2.1.2(4mo ago)210.2k↓81.3%2[1 issues](https://github.com/Slamdunk/psql-php/issues)MITPHPPHP ~8.4.0 || ~8.5.0CI passing

Since Sep 4Pushed 1w ago1 watchersCompare

[ Source](https://github.com/Slamdunk/psql-php)[ Packagist](https://packagist.org/packages/slam/psql-php)[ Fund](https://paypal.me/filippotessarotto)[ GitHub Sponsors](https://github.com/Slamdunk)[ RSS](/packages/slam-psql-php/feed)WikiDiscussions master Synced yesterday

READMEChangelog (9)Dependencies (5)Versions (12)Used By (0)

`psql` in PHP
=============

[](#psql-in-php)

[![Latest Stable Version](https://camo.githubusercontent.com/f808ce2bcef25d02633dff3f6f725fd38639990334e58305ce8bb884249471fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736c616d2f7073716c2d7068702e737667)](https://packagist.org/packages/slam/psql-php)[![Downloads](https://camo.githubusercontent.com/c29cd1934f2b0130f93f08e7baa84df3ec3f8f359c2bba58e83d00b8fa22fc9b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736c616d2f7073716c2d7068702e737667)](https://packagist.org/packages/slam/psql-php)[![Integrate](https://github.com/Slamdunk/psql-php/workflows/CI/badge.svg?branch=master)](https://github.com/Slamdunk/psql-php/actions)[![Code Coverage](https://camo.githubusercontent.com/7c1daf91c7ea7363c57c148df91d8ba0c40266563f82627ae62ad0ddef50dc2a/68747470733a2f2f636f6465636f762e696f2f67682f536c616d64756e6b2f7073716c2d7068702f636f7665726167652e7376673f6272616e63683d6d6173746572)](https://codecov.io/gh/Slamdunk/psql-php?branch=master)

PHP light version of `psql` that comes with PostgreSQL.

Why
---

[](#why)

1. You are inside a PHP only environment, like a PHP Docker image
2. You need to import a large `pg_dump --inserts` dump
3. You don't have access to the native `psql` client

Performance
-----------

[](#performance)

Speed is exactly the **same** of the original `psql` binary thanks to streams usage.

Supported formats
-----------------

[](#supported-formats)

Input typeExampleSupported?`pg_dump` output (with `COPY` commands)*as is*❌`pg_dump --inserts` output*as is*✔️Single query on single line`SELECT NOW();`✔️Single query on multiple lines`SELECT`
`NOW();`✔️Multiple queries on separated single or multiple lines`SELECT NOW();`
`SELECT`
`NOW();`✔️Multiple queries on single line`SELECT NOW();SELECT NOW();`❌When using `pg_dump --inserts` it is highly recommended to also set `--rows-per-insert=1000` to speed performances up.

Usage
-----

[](#usage)

The library provides two usages, the binary and the `\SlamPsql\Psql` class.

### From CLI

[](#from-cli)

```
$ ./psql -h
Usage: psql [OPTIONS]
  -h, --host              Connect to host
  -p, --port              Port number
  -U, --username          User for login
  -d, --dbname            Database to use
	  --connect_timeout   Connect timeout to use, in seconds

  Use `PGPASSWORD` env variable to set the connection password.

$ printf "CREATE DATABASE foobar;\nSELECT datname FROM pg_database;" | ./psql
foobar

$ ./psql --database foobar < foobar_huge_dump.sql

```

### From PHP

[](#from-php)

```
$psql = new \SlamPsql\Psql('localhost', 5432, 'my_username', 'my_password', 'my_database');
$return = $psql->run(\STDIN, \STDOUT, \STDERR);
exit((int) (true !== $return));

// With the connect_timeout argument
$psql = new \SlamPsql\Psql('localhost', 5432, 'my_username', 'my_password', 'my_database', 5);
$return = $psql->run(\STDIN, \STDOUT, \STDERR);
exit((int) (true !== $return));
```

`\SlamPsql\Psql::run` accepts any type of resource consumable by `fgets/fwrite` functions.

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance78

Regular maintenance activity

Popularity28

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 92.1% of commits — single point of failure

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 ~112 days

Recently: every ~33 days

Total

9

Last Release

133d ago

Major Versions

v1.4.0 → v2.0.02025-10-16

PHP version history (4 changes)v1.0.0PHP ~8.1.0 || ~8.2.0

v1.2.0PHP ~8.2.0 || ~8.3.0

v1.3.0PHP ~8.3.0 || ~8.4.0

v2.1.0PHP ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/50348?v=4)[Sahn Lam](/maintainers/Slam)[@slam](https://github.com/slam)

---

Top Contributors

[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (327 commits)")[![Slamdunk](https://avatars.githubusercontent.com/u/152236?v=4)](https://github.com/Slamdunk "Slamdunk (24 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")

---

Tags

phppostgresqlpsqlpostgrespsql

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/slam-psql-php/health.svg)

```
[![Health](https://phpackages.com/badges/slam-psql-php/health.svg)](https://phpackages.com/packages/slam-psql-php)
```

###  Alternatives

[patricktalmadge/bootstrapper

Twitter Bootstrap markup generator

555412.9k4](/packages/patricktalmadge-bootstrapper)[orptech/laravel-migration-partition

Laravel extensions that extends Illuminate to enable partitioned table creation within Laravel migrations.

3829.0k](/packages/orptech-laravel-migration-partition)

PHPackages © 2026

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