Connecting PHP and PostgreSQL: Expanding Timescale Integrations
PostgreSQL has long been praised for its language-agnostic design—but when it comes to real-world development, each language ecosystem has its own expectations for how databases should work. That’s why we’re expanding our integration efforts, starting with first-class support for PHP when using PostgreSQL with TimescaleDB. Our goal: make Timescale a seamless, idiomatic part of your stack—no matter what language you work in. PHP is a versatile, easy-to-learn server-side language with built-in web development features, a vast ecosystem, strong database integration, and excellent community support, making it ideal for dynamic web applications. By integrating it with PostgreSQL and TimescaleDB, we will enable developers to build efficient, reliable, and data-driven applications with ease. How to Connect PHP and PostgreSQL SQL is cool, but at the end of the day, developers prefer to write their favorite programming language. Tobias Petry, who is highly involved in the Laravel ecosystem, leads our PHP and PostgreSQL integration. Let’s have a look at the simple setup for the PHP integration. return new class extends Migration { public function up(): void { Schema::createExtensionIfNotExists('timescaledb'); Schema::create('visits', function (Blueprint $table) { $table->identity(); $table->bigInteger('website_id'); $table->text('url'); $table->float('duration'); $table->timestampTz('created_at'); $table->primary(['id', 'created_at']); $table->index(['website_id', 'created_at']); $table->timescale( new CreateHypertable('created_at', '1 day'), new CreateReorderPolicyByIndex('website_id', 'created_at'), new EnableCompression(segmentBy: 'website_id'), new CreateCompressionPolicy('3 days'), new CreateRetentionPolicy('1 year'), new EnableChunkSkipping('id'), ); }); Schema::continuousAggregate('visits_agg', function(CaggBlueprint $table) { $table->as(" SELECT time_bucket('1 hour', created_at) AS bucket, website_id, url, SUM(duration) AS duration FROM visits GROUP BY bucket, website_id, url "); $table->realtime(); $table->index(['website_id','url']); $table->timescale( new CreateRefreshPolicy('5 minutes', '1 days', '2 hours'), new EnableCompression(), new CreateCompressionPolicy('2 days'), ); }); } };  If you like this, consider giving the project a GitHub star! ⭐️ You’ll also find more integration tips and information. In addition to the PHP/PostgreSQL integration, Tobias is producing a new course, “Making Analytics FAST—Learn Timescale.” Stay tuned! Why Language-Specific Integrations Matter While TimescaleDB works with any language that connects to PostgreSQL, we believe in going beyond basic compatibility. Language-specific integrations deliver a number of benefits: **Idiomatic implementations **that follow community best practices Simplified developer experience with familiar patterns and tooling Performance optimizations tailored to language-specific ORMs and drivers Documentation that speaks your language, with relevant examples and use cases Our goal isn't just to be compatible with your stack—it's to become an essential, natural extension of it. Want to create your own integration? Read the integration guide. Are you building an integration for TimescaleDB in your preferred language? We'd love to hear about it! Share your project or reach out to our Ecosystem team directly.

PostgreSQL has long been praised for its language-agnostic design—but when it comes to real-world development, each language ecosystem has its own expectations for how databases should work.
That’s why we’re expanding our integration efforts, starting with first-class support for PHP when using PostgreSQL with TimescaleDB. Our goal: make Timescale a seamless, idiomatic part of your stack—no matter what language you work in.
PHP is a versatile, easy-to-learn server-side language with built-in web development features, a vast ecosystem, strong database integration, and excellent community support, making it ideal for dynamic web applications. By integrating it with PostgreSQL and TimescaleDB, we will enable developers to build efficient, reliable, and data-driven applications with ease.
How to Connect PHP and PostgreSQL
SQL is cool, but at the end of the day, developers prefer to write their favorite programming language. Tobias Petry, who is highly involved in the Laravel ecosystem, leads our PHP and PostgreSQL integration.
Let’s have a look at the simple setup for the PHP integration.
return new class extends Migration
{
public function up(): void
{
Schema::createExtensionIfNotExists('timescaledb');
Schema::create('visits', function (Blueprint $table) {
$table->identity();
$table->bigInteger('website_id');
$table->text('url');
$table->float('duration');
$table->timestampTz('created_at');
$table->primary(['id', 'created_at']);
$table->index(['website_id', 'created_at']);
$table->timescale(
new CreateHypertable('created_at', '1 day'),
new CreateReorderPolicyByIndex('website_id', 'created_at'),
new EnableCompression(segmentBy: 'website_id'),
new CreateCompressionPolicy('3 days'),
new CreateRetentionPolicy('1 year'),
new EnableChunkSkipping('id'),
);
});
Schema::continuousAggregate('visits_agg', function(CaggBlueprint $table) {
$table->as("
SELECT
time_bucket('1 hour', created_at) AS bucket,
website_id,
url,
SUM(duration) AS duration
FROM visits
GROUP BY bucket, website_id, url
");
$table->realtime();
$table->index(['website_id','url']);
$table->timescale(
new CreateRefreshPolicy('5 minutes', '1 days', '2 hours'),
new EnableCompression(),
new CreateCompressionPolicy('2 days'),
);
});
}
};

If you like this, consider giving the project a GitHub star! ⭐️ You’ll also find more integration tips and information.
In addition to the PHP/PostgreSQL integration, Tobias is producing a new course, “Making Analytics FAST—Learn Timescale.” Stay tuned!
Why Language-Specific Integrations Matter
While TimescaleDB works with any language that connects to PostgreSQL, we believe in going beyond basic compatibility. Language-specific integrations deliver a number of benefits:
- **Idiomatic implementations **that follow community best practices
- Simplified developer experience with familiar patterns and tooling
- Performance optimizations tailored to language-specific ORMs and drivers
- Documentation that speaks your language, with relevant examples and use cases
Our goal isn't just to be compatible with your stack—it's to become an essential, natural extension of it.
Want to create your own integration? Read the integration guide.
Are you building an integration for TimescaleDB in your preferred language? We'd love to hear about it! Share your project or reach out to our Ecosystem team directly.