Download the PHP package brokenice/laravel-pgsql-partition without Composer
On this page you can find all versions of the php package brokenice/laravel-pgsql-partition. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download brokenice/laravel-pgsql-partition
More information about brokenice/laravel-pgsql-partition
Files in brokenice/laravel-pgsql-partition
Package laravel-pgsql-partition
Short Description PostgreSQL Partition extension for Laravel.
License MIT
Informations about the package laravel-pgsql-partition
Laravel PostgreSQL Partition
Laravel-pgsql-partition is a useful Laravel package to easily work with PostgreSQL Table Partitioning. Partitioning requires PostgreSQL version >= 10.0.
Installation
Add the package using composer:
For Laravel versions before 5.5 or if not using auto-discovery, register the service provider in config/app.php:
Quickstart
Create a partitioned table migration
From the command line:
Then edit the migration you just created:
Run the migration:
Partition Types Support
PostgreSQL supports these partitioning methods:
| Type | Description |
|---|---|
| RANGE | Partition based on a range of values |
| LIST | Partition based on a list of discrete values |
| HASH | Partition based on hash of the partition key |
Usage Examples
Partition by RANGE
This type of partitioning assigns rows to partitions based on column values falling within a given range.
Partition by LIST
Similar to partitioning by RANGE, except that the partition is selected based on columns matching one of a set of discrete values.
Partition by HASH
With this type of partitioning, a partition is selected based on the hash of the partition key.
Partition by YEARS
Convenience method to partition a table by year ranges:
Partition by YEARS AND MONTHS
Create partitions for each month within a year range:
Partition Maintenance
Detach a Partition
Detaching a partition keeps the data but removes it from the partitioned table:
Attach a Partition
Attach an existing table as a partition:
Drop a Partition
Permanently delete a partition and its data:
Truncate a Partition
Remove all data from a partition:
Vacuum (Optimize)
Reclaim storage and update statistics:
Analyze
Update query planner statistics:
Reindex
Rebuild indexes on a partition:
Querying Partitions with Eloquent
Create a Model
Query a Specific Partition
In PostgreSQL, partitions are separate tables, so you can query them directly:
Query Multiple Partitions
Using MultipleSchemaModel
For multi-schema support:
Artisan Commands
This package provides a set of artisan commands for partition management:
Available Actions
| Action | Description |
|---|---|
list |
List all partitions for a table |
create |
Create partitions on an existing partitioned table |
detach |
Detach a partition (keeps data) |
attach |
Attach a table as a partition |
drop |
Drop a partition (deletes data) |
truncate |
Truncate partition data |
vacuum |
Run VACUUM on partitions |
analyze |
Run ANALYZE on partitions |
reindex |
Run REINDEX on partitions |
Examples
Options
| Option | Description |
|---|---|
--schema |
PostgreSQL schema (default: public) |
--table |
Parent table name |
--method |
Partition method: RANGE, LIST, HASH, YEAR, MONTH, YEAR_MONTH |
--column |
Column to partition by |
--number |
Number of partitions (for HASH) |
--partitions |
Partition names (comma-separated) |
--excludeDefault |
Don't create a default partition |
--from |
Start value for RANGE partition |
--to |
End value for RANGE partition |
--full |
Use VACUUM FULL |
PostgreSQL vs MySQL Partitioning
Key differences from the MySQL version of this package:
| Feature | MySQL | PostgreSQL |
|---|---|---|
| Partition creation | ALTER TABLE on existing | At CREATE TABLE or separate CREATE TABLE ... PARTITION OF |
| Future values | MAXVALUE | DEFAULT partition |
| Subpartitions | Native support | Partition of partition |
| KEY partitioning | Supported | Use HASH instead |
| Maintenance | OPTIMIZE, REPAIR, REBUILD | VACUUM, ANALYZE, REINDEX |
Important Notes
-
PostgreSQL 10+ Required: Native declarative partitioning requires PostgreSQL 10 or higher.
-
Primary Keys: In PostgreSQL, the partition key must be included in any primary key or unique constraint.
-
Auto-increment: Use
BIGSERIALfor auto-increment columns, but include the partition key in the primary key: -
Indexes: Each partition maintains its own indexes. Create indexes on the parent table and they'll be automatically created on partitions.
- Default Partition: Always consider adding a default partition to catch rows that don't match any other partition.
Tests
For integration tests (requires PostgreSQL):
Contributing
Recommendations and pull requests are most welcome! Pull requests with tests are the best!
Credits & License
laravel-pgsql-partition is owned and maintained by Luca Becchetti
As open source creation any help is welcome!
The code of this library is licensed under MIT License; you can use it in commercial products without any limitation.
The only requirement is to add a line in your Credits/About section with the text below:
All versions of laravel-pgsql-partition with dependencies
ext-pdo Version *
ext-json Version *
illuminate/database Version ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
ext-mbstring Version *
ext-pdo_pgsql Version *