Postgresql Rails Partitioning
Tag: Ruby
Tag: Rails
Category: jekyll
Category: update
Category: git
Category: database
Category: PostgreSQL
Category: websocket
Category: ruby
Category: projects
Category: Redis
Category: mysql
Category: Mac
Category: Node
Category: NPM
Category: PM2
Category: nodejs
Category: Meteor
Category: Nginx
Category: gitLab
Category: Rails
- Why Ruby on Rails is better than Python Django?
- How to use Hotwire turbo in Rails 6 with Webpacker?
- Rails 6 Credentials (master.key and credentials.yml.enc)
- Rails Console
- JIRA-Atlassian-Connect-App-Django
- Rails 4 5.0 Session Cookie AuthenticityToken
- Rails Active Storage
- Rails 5 Source code Research
- 微信支付
- Rails零星笔记
Category: Homebrew
Category: CentOS
Category: FreeSwitch
Category: Ruby
- Ruby on Rails 8
- RESTful API
- Ruby on Rails 7
- Study from Ruby official website
- Ruby-Metaprogramming
- Ruby连数据库的问题
- rbenv使用
Category: Vim
Category: javascript
Category: React-Native
Category: Wechat
Category: homeland
Category: JavaScript
Category: Docker
Category: RubyMine
Category: Authorization
Category: RESTful-API
Category: Proxy
Category: Deploy
Category: Devise
Category: Bootstrap
Category: Active_Storage
Category: github
Category: Android
Category: cloud
Category: ssh
Category: python
Category: reactjs
Category: markdown
Category: ShadowSocks
Category: Code
Category: rails
Category: code
Category: Django
Category: Python
Category: DRF
Category: Fish
Category: Yarn
Category: Material-UI
Category: CSS
Category: aws
Category: uwsgi
Category: nginx
Category: docker
Category: React
Category: Enzyme
Category: Jira
Category: Interview
Category: JetBrain
Category: PyCharm
Category: ESLint
Category: Rails6
Category: NVM
Category: ssl
Category: tencent
Category: CI
Category: jenkins
Category: GitHub
Category: Credentials
Category: master.key
Category: Webpacker
Category: Turbo
Category: Hotwire
Category: Bootstrap5
Category: Flutter
Category: Clash
Category: Tor
Category: proxy
Category: Build
Category: SwitchyOmega
Category: Chrome-extension
Category: SQLAlchemy
Category: Algorithm
Category: Rails7
Category: Data
Category: Structure
Category: CPP
Category: Languages
Category: Golang
Category: Typescript
Category: Rails 8
layout: post title: “Rails PostgreSQL Partitioning” date: 2016-07-14 14:40:24 categories: Ruby —
https://www.postgresql.org/docs/9.5/static/ddl-inherit.html 表继承
https://www.postgresql.org/docs/9.5/static/ddl-partitioning.html 分表技术
https://github.com/fiksu/partitioned Rails中实现PostgreSQL分表技术的gem
https://www.postgresql.org/docs/9.1/static/ddl-schemas.html Schema
用PostgreSQL的表继承, 主表customers只定义表的结构, 不存储任何数据。分表继承主表customers, 一个分表只存储该企业的customers。分表命名为: p60382。
分表在schema employees_partitions中, 其它PostgreSQL表在public schema中, 更方便管理, 不会出现表太多使得用pgadmin等工具不方便找表的问题。
Ensure that the constraint_exclusion configuration parameter is not disabled in postgresql.conf. If it is, queries will not be optimized as desired.
Customer.create_infrastructure
(0.8ms) select count(*) from pg_namespace where nspname = 'customers_partitions'
(14.6ms) CREATE SCHEMA customers_partitions
(23.2ms) CREATE OR REPLACE FUNCTION always_fail_on_insert(table_name text) RETURNS boolean
LANGUAGE plpgsql
AS $$
BEGIN
RAISE EXCEPTION 'partitioned table "%" does not support direct inserts, you should be inserting directly into child tables', table_name;
RETURN false;
END;
$$;
(5.8ms) CREATE OR REPLACE RULE customers_insert_redirector AS
ON INSERT TO customers
DO INSTEAD
(
SELECT always_fail_on_insert('customers')
)