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. slam/psql-php

ActiveLibrary

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

PHP version of psql cli that comes with PostgreSQL

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

Since Sep 4Pushed 1mo 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 1mo ago

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

49

—

FairBetter than 95% of packages

Maintenance76

Regular maintenance activity

Popularity28

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 91.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

88d 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] (288 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

[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58723.9M36](/packages/scienta-doctrine-json-functions)[martin-georgiev/postgresql-for-doctrine

Extends Doctrine with native PostgreSQL support for arrays, JSONB, ranges, PostGIS geometries, text search, ltree, uuid, and 100+ PostgreSQL-specific functions.

4485.3M4](/packages/martin-georgiev-postgresql-for-doctrine)[aura/sql

A PDO extension that provides lazy connections, array quoting, query profiling, value binding, and convenience methods for common fetch styles. Because it extends PDO, existing code that uses PDO can use this without any changes to the existing code.

5632.5M43](/packages/aura-sql)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4572.9M34](/packages/aura-sqlquery)[ruckusing/ruckusing-migrations

Framework for generating and managing database migrations

502997.8k8](/packages/ruckusing-ruckusing-migrations)[phpbu/phpbu

PHP Backup utility.

1.3k89.0k4](/packages/phpbu-phpbu)

PHPackages © 2026

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