最近一个带有重要数据库的数据库服务器坏了(一些我不想解决的 grub linux 问题)。
我仍然可以访问文件系统。是否有机会通过仅将一些包含内容的目录移动到相同的机器来传输数据库?
这是一个带有 postgres 8.4 的 32 位 ubuntu 10.04
编辑:在 ubuntu 10,04 上,postgresql 数据目录是/var/lib/postgresql/8.4/main而不是/usr/local/pgsql/data
查看文档,我没有看到任何提及行级加密的内容。
假设我有一个需要锁定的高度机密信息数据库。如何在 postgres 中实现行级加密的表?行级失败,我能做的下一个最好的事情是什么,缺点是什么?
这是表定义
Table "public.kb_article_contents"
Column | Type | Modifiers
------------+----------+-----------
article_id | smallint | not null
contents | text | not null
keywords | text | not null
Indexes:
"contents_idx" gin (to_tsvector('english'::regconfig, contents))
Foreign-key constraints:
"kb_article_contents_article_id_fkey" FOREIGN KEY (article_id) REFERENCES kb_articles(id)
Run Code Online (Sandbox Code Playgroud)
和查询
support=> EXPLAIN ANALYSE
SELECT
id,
-- if we remove the next line runtimes speeds up (and of course the order by)
ts_rank(to_tsvector( 'english', contents ), plainto_tsquery('string')) AS rank
FROM
kb_article_contents
INNER JOIN kb_articles
ON ( kb_article_contents.article_id = kb_articles.id ) …Run Code Online (Sandbox Code Playgroud) 我创建了一个许多用户可以共享的角色:
> create role foo_read_only connection limit 5;
Run Code Online (Sandbox Code Playgroud)
然后我为该角色分配了权限:
> grant select on table1 to foo_read_only;
Run Code Online (Sandbox Code Playgroud)
然后我将该角色分配给了人们:
> grant foo_read_only to fred;
> grant foo_read_only to ginger;
Run Code Online (Sandbox Code Playgroud)
问题: fred 和ginger 的连接限制是5,还是他们之间共享这个限制?
谢谢!
在从云故障中恢复时,我发现PostgreSQL数据库中的某些表行为异常。这些表使用主键编制索引,但pg_dump产生重复字段,pg_restore在备份服务器上失败。
我试图REINDEX:
REINDEX INDEX rank_details_pkey;
ERROR: could not create unique index "rank_details_pkey"
DETAIL: Table contains duplicated values.
Run Code Online (Sandbox Code Playgroud)
指数定义为:
<table info here>
Indexes:
"rank_details_pkey" PRIMARY KEY, btree (user_id)
Run Code Online (Sandbox Code Playgroud)
而且,奇怪的是,
SELECT user_id, COUNT(*) FROM <table name> GROUP BY 1 HAVING COUNT(*) > 1;
user_id | count
---------+-------
(0 rows)
Run Code Online (Sandbox Code Playgroud)
总而言之 - 我的表中有重复的值,无法找到或清除。
任何想法如何解决这一问题?这是一个生产服务器,所以所有修复都应该在不影响服务的情况下完成。
根据我的 Postgres (8.4.2) 版本的文档,pg_dump 可以“以脚本或存档文件格式输出”。脚本格式的转储 (4GB) 需要 1.5 小时才能恢复,我想知道存档格式是否更快。
顺便说一下,我的脚本格式转储正在使用 COPY 命令,所以我不是一次插入一个。
提前致谢。
在具有许多公司的数据库中,使用schema和search_path
几乎所有访问都来自公司级别,即仅限于单个模式。一些数据仓库和会计功能需要扫描所有模式。
对于这个问题,根据@horse_with_no_name 的最佳建议,使用模式本身作为分区。例如
create table global.usr(
usr_id int primary key, // these will be unique across all partitions
name varchar );
create table cmp1.usr(
usr_id int primary key,
) inherits( global.usr );
create table cmp2.usr(
....
Run Code Online (Sandbox Code Playgroud)
如果我们填充
insert into cmp1 usr values( 11, 'eleven' );
insert into cmp1 usr values( 12, 'twelve' );
insert into cmp2 usr values( 21, 'twenty-one' );
insert into cmp2 usr values( 22, 'twenty-two' );
insert into cmp3 usr values( 31, 'thirty-one' …Run Code Online (Sandbox Code Playgroud) 出于某种原因,我的 PostgreSQL 从站不再流式复制主站上的更改。之前可以用,有段时间了,最近发现slave的数据库内容很旧,slave的日志文件有错误,分别是“无效幻数0000 ”和“乱序时间线ID 1(之后2) ”。
你知道我该如何解决这个问题吗?或者为什么会发生?
详情如下。
日志文件错误消息:(在从站上,pg_log/postgresql-Sat.log)
LOG: entering standby mode
LOG: redo starts at 0/1C78848
LOG: consistent recovery state reached at 0/1C7FA30
LOG: database system is ready to accept read only connections
LOG: invalid magic number 0000 in log file 0, segment 1, offset 14942208
LOG: streaming replication successfully connected to primary
LOG: out-of-sequence timeline ID 1 (after 2) in log file 0, segment 1, offset 0
FATAL: terminating walreceiver process due to administrator …Run Code Online (Sandbox Code Playgroud) 我有以下形式的查询:
SELECT * FROM twitter_personas WHERE twitter_user_id IN ($1, $2, $3, ..., $25000)
Run Code Online (Sandbox Code Playgroud)
IN 查询有 10 到 25000 个值。查询一次运行几分钟。我有近 500,000 个这样的查询要运行。
twitter_user_id 列已编入索引。关于如何加快速度的任何想法?
# \d twitter_personas
Table "public.twitter_personas"
Column | Type | Modifiers
------------------+------------------------+------------------------------------------------------------
persona_id | uuid | not null
twitter_user_id | bigint |
screen_name | character varying(40) | not null
avatar_url | text |
hashval | integer | not null default nextval('personas_hashval_seq'::regclass)
Indexes:
"twitter_personas_pkey" PRIMARY KEY, btree (persona_id)
"index_twitter_personas_on_screen_name" UNIQUE, btree (screen_name)
"index_twitter_personas_on_screen_name_persona_id" btree (screen_name, persona_id)
"index_twitter_personas_twitter_user_id" btree (twitter_user_id) …Run Code Online (Sandbox Code Playgroud) 我对 PostgreSQL 中的表空间感到困惑。是不是类似于 LVM?我的意思是当磁盘已满时,我们可以添加另一个磁盘,然后格式化CREATE TABLESPACE tblspace LOCATION /media/disk2/data吗?够了吗?或者我们应该手动使用ALTER数据库、表或索引来利用它?
postgresql ×10
backup ×2
encryption ×1
migration ×1
performance ×1
permissions ×1
primary-key ×1
replication ×1
restore ×1
tablespaces ×1