GithubHelp home page GithubHelp logo

How to list partition tables? about pg_party HOT 1 CLOSED

rkrage avatar rkrage commented on July 22, 2024
How to list partition tables?

from pg_party.

Comments (1)

rkrage avatar rkrage commented on July 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.