Gna*_*nam 18 postgresql partitioning postgresql-9.1 archive
继续我在上发布的一个问题,将高容量和高访问率的表移动到单独的数据库是个好主意吗?,我正在寻找可用于 PostgreSQL 数据库归档的不同技术/解决方案。
我能想到的几个解决方案是:
任何其他建议/指针/解决方案都非常受欢迎和赞赏。
注意:我们在 CentOS5.2 上运行 PostgreSQL v9.1.3
suf*_*leR 14
我对存档的建议:
archive_tablespace(如果您愿意,可以在存档中分离硬件)创建表。例如,我们要归档表格帖子。
create table posts_all ( LIKE public.posts) ;
create table posts_archive () inherits ( public.posts_all) ;
alter table public.posts inherits ( public.posts_all ) ;
Run Code Online (Sandbox Code Playgroud)
之后,我们将有 2 个新表:public.posts_all(具有与帖子中相同的列)查询所有帖子(存档和生产)和 public.posts_archive 查询所有存档帖子。Public.posts 将从posts_all 继承。
插入应该以旧方式进行(到表 public.posts),除非您将在 posts_all 上编写触发器以将插入重定向到帖子表。如果你有分区,它会更复杂。使用工作应用程序和旧数据迁移之前,您无需更改应用程序代码中的任何内容即可使用此方法。
创建用于逻辑分离的架构存档。如果可能,我的建议是将存档数据按某个时间段(年或月)分开(archive_2005)。
在 archive_year 架构中创建归档表
create table archive_2005.posts (
check(record_date >= '2005-01-01 00:00:00'::timestamp
and record_date < '2006-01-01 00:00:00'::timestamp)
) inherits (posts_archive) tablespace archive_tablesapce;
Run Code Online (Sandbox Code Playgroud)
之后,您将在架构 archive_2005 中拥有新表帖子,并且 postgresql planer 将知道该数据仅在设计的时间段内存在。如果按其他时间段查询,postgresql 将不会在此表中搜索。
创建函数/过程/触发器以将数据移动到存档表。
如果实施:
archive_tablespace或只是将其更改为从 posts_archive 继承(我没有对此进行测试)这是通用技术,您应该根据自己的需要进行调整。有什么建议可以改进吗?
进一步阅读:PostgreSQL 继承、分区
| 归档时间: |
|
| 查看次数: |
11274 次 |
| 最近记录: |