Comments (1)
Programmatically, there isn't currently a way to figure out the range for a given partition. From a psql console, though, you should be able to see attached partitions and their associated metadata:
psql=# \d+ bigint_date_ranges
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
------------+-----------------------------+-----------+----------+------------------------------------------------+---------+--------------+-------------
id | bigint | | not null | nextval('bigint_date_ranges_id_seq'::regclass) | plain | |
created_at | timestamp without time zone | | not null | | plain | |
updated_at | timestamp without time zone | | not null | | plain | |
Partition key: RANGE (((created_at)::date))
Partitions: bigint_date_ranges_a FOR VALUES FROM ('2018-03-26') TO ('2018-03-27'),
bigint_date_ranges_b FOR VALUES FROM ('2018-03-27') TO ('2018-03-28')
Also, keep in mind that it is possible to manually name your child partitions to avoid these cryptic names:
create_range_partition_of \
:some_range_records,
name: :some_range_records_descriptive_partition_name,
partition_key: "created_at::date",
start_range: current_date,
end_range: current_date + 1.day
Generally, it's a good idea to create necessary partitions ahead of time (via cron or some other scheduling service). As far as automatic partition creation goes, that isn't natively supported but can be accomplished with the rescuing you described. Example:
user_item = UserItem.new(user_id: 1)
begin
user_item.save!
rescue ActiveRecord::StatementInvalid => e
if e.message =~ /no partition of relation/
UserItem.create_partition(values: user_item.user_id)
user_item.save!
else
raise e
end
end
from pg_party.
Related Issues (20)
- Multiple Key Partition HOT 3
- Update readme for 1.2.0 release
- Question: schema_exclude_partitions = false development workflow HOT 7
- Feature request: select range partitions by one of date HOT 3
- Fix ruby 2.7 keyword argument warnings HOT 2
- Use #create_list_partition_of in rake task? HOT 1
- Partition by ForeignKey? HOT 11
- rspec tests fail unless using structure.sql HOT 2
- Explanation needed: Are many "partition tables" a problem? HOT 2
- Convert a normal table to partitioned table HOT 2
- ActiveRecord doesn't support composite primary keys? HOT 4
- Rails 6.1 support HOT 2
- Address Rails 6.1 deprecation warnings HOT 2
- Any talks to move some of these features into Rails core? HOT 7
- No changelog entry for 1.5.0 HOT 3
- The way I setup on Rails 6.1 HOT 1
- Migration from `partitioned` gem to `pg_party` HOT 1
- pg_dump: error: cross-database references are not implemented HOT 1
- create_range_partition and Ruby 3 HOT 7
- Migrating from 0.7.3 to 1.6.0 process HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pg_party.