我的 PostgreSQL 默认端口是 5432,我想通过使用命令行(在 Windows 7 中)更改默认端口。
我之前看到过这个解决方案:https : //stackoverflow.com/questions/187438/want-to-change-pgsql-port
我尝试运行以下命令,但失败了:
postgres --p 5431
Run Code Online (Sandbox Code Playgroud)
有人能告诉我如何使用命令行更改端口吗?
在数据库中存储单个记录的元数据的最佳实践是什么?
我需要在我的数据库中存储许多表的常见元数据,例如创建时间和上次更新时间。我找到了几种不同的解决方案:
将元数据直接存储在表中。
优点:
缺点:
创建一个通用元数据表,并使用软外键将数据链接到正确的表和记录。
优点:
缺点:
为每个需要元数据的表创建单独的元数据表。
优点:
缺点:
是否有比我在这里提到的更多的选择、优点或缺点?存储这些元数据的最佳实践是什么?
我已经在运行 Ubuntu 12.04 和 13.04 的 2 个虚拟机上从 APT 存储库成功安装了 PostgreSQL 9.3……但是,我无法在运行 Ubuntu 12.04 的主机上正确安装它。
安装(这次)似乎没问题,但也许有一个我不明白的错误:
* No PostgreSQL clusters exist; see "man pg_createcluster"
Setting up postgresql-9.3 (9.3.0-2.pgdg12.4+1) ...
Creating new cluster 9.3/main ...
config /etc/postgresql/9.3/main
data /var/lib/postgresql/9.3/main
locale en_US.UTF-8
port 5432
update-alternatives: using /usr/share/postgresql/9.3/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode.
Run Code Online (Sandbox Code Playgroud)
所以我然后尝试将自己添加为 PostgreSQL 用户,但我得到了这个:
createuser: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections …Run Code Online (Sandbox Code Playgroud) 当我使用 MySQL 时,我可以运行一个命令,将 SSH 连接到我的服务器并将数据库复制到我的本地机器上。
ssh -t remoteserver 'mysqldump --compress -u dbuser --password="password" db_name' | /usr/local/mysql/bin/mysql -u root --password="password" local_db_name
Run Code Online (Sandbox Code Playgroud)
我如何用 PostgreSQL 做同样的事情?
我需要将一些随机值放入数据库,但我不想最终得到完全随机的文本(如 7hfg43d3)。相反,我想随机选择自己提供的值之一。
我正在处理复杂的问题,但我会将其简化为这个问题。
我有两张桌子
A [ID, column1, column2, column3]
B [ID, column1, column2, column3, column4]
Run Code Online (Sandbox Code Playgroud)
我想更新第三个:
C [ID, column1, column2,column3]
Run Code Online (Sandbox Code Playgroud)
我正在使用此查询更新另一个第三个表。
UPDATE C
set column1=t.firstTab, column2=t.secondTab, column3=t.thirdTab
from (select A.column1 as firstTab, B.column2 as secTab,
(A.column1 + B.column2) thirdTab
from A, B limit 1; ) as t ;
Run Code Online (Sandbox Code Playgroud)
我有:
UPDATE 0
Run Code Online (Sandbox Code Playgroud)
当我运行此查询时:
select A.column1 as firstTab, B.column2 as secTab, (A.column1 + B.column2) thirdTab
from A, B limit 1;
Run Code Online (Sandbox Code Playgroud)
我得到了结果。我错过了什么吗?
示例数据:http : //sqlfiddle.com/#!15/e4d08/5
我在 SQL 中对电气原理图建模时遇到了一些麻烦。我想捕获的结构是
part ??????????? pin
? ?
part_inst ?????? pin_inst
Run Code Online (Sandbox Code Playgroud)
其中“inst”是“instance”的缩写。
例如,我可能part将 LM358 运算放大器pin用作 1OUT、1IN-、1IN+、GND、2IN+、2IN-、2OUT 和 V CC。然后我可能会将这部分放在原理图上,创建 apart_inst和 8
pin_insts。
忽略数据字段,我对模式的最初尝试是
create table parts (
part_id bigserial primary key
);
create table pins (
pin_id bigserial primary key,
part_id bigint not null references parts
);
create table part_insts (
part_inst_id bigserial primary key,
part_id bigint not null references parts
);
create table pin_insts (
pin_inst_id bigserial primary key,
part_inst_id bigint …Run Code Online (Sandbox Code Playgroud) postgresql foreign-key database-design referential-integrity polymorphic-associations
我有一个 PostgreSQL 表Prices,包含以下列:
price (十进制)product_id (国际)还有created_at和updated_at列。
价格会定期更新,我会在表中保留旧价格。对于给定的产品,表中的最后一个价格是当前价格。
获得特定产品最后价格的最有效方法是什么:
product_id和查询最后一条记录active(布尔值)以标记最新价格并创建复合索引(product_id和active)我有一个处于恢复模式的 PostgreSQL 独立实例。一直在说
2014-03-24 18:45:57 MDT FATAL: the database system is starting up
Run Code Online (Sandbox Code Playgroud)
几个小时,并ps显示:
postgres 2637 0.1 0.1 116916 4420 ? Ds 15:43 0:18 postgres: startup process recovering 00000001000000040000007E
Run Code Online (Sandbox Code Playgroud)
有没有办法观察恢复的进度,最好是使用 ETA?我怎样才能让这个过程“解除卡住”?
我可以使用标准的启动/停止脚本停止 postgres,但是当我再次启动它时,它仍然停留在恢复模式。
Debian 7.4、Linux 内核 3.2.0、PostgreSQL 9.1.12
的输出strace -p 2637:
Process 2637 attached - interrupt to quit
close(154) = 0
getppid() = 2600
open("pg_clog/0003", O_RDWR|O_CREAT, 0600) = 154
lseek(154, 221184, SEEK_SET) = 221184
write(154, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192) = 8192
fsync(154) = 0
Run Code Online (Sandbox Code Playgroud)
上面的输出似乎无限重复。
一个 gdb 回溯(随后的三个 …
我需要从另一个表更新一个表,我需要更新所有列。除了列出SET子句中的每一列之外,有没有办法一次更新它们?像这样:
update tableA
set * = tableB.*
from tableB where tableA.id = tableB.id
Run Code Online (Sandbox Code Playgroud)
我在 psql 中尝试过,它不起作用。我必须像这样列出每一列:
update tableA
set c1 = tableB.c1, c2 = tableB.c2, ...
from tableB where tableA.id = tableB.id
Run Code Online (Sandbox Code Playgroud)
tableB创建使用create .. like tableA. 所以它们基本上是相同的。我这样做的原因是我需要将 .csv 数据加载到临时表tableB,然后tableA根据.csv 中的新数据进行更新tableB。tableA需要尽量少加锁,tableA需要保持完整性。我不确定“删除然后插入”是否是一个不错的选择?
postgresql ×10
update ×2
command-line ×1
foreign-key ×1
join ×1
metadata ×1
random ×1
recovery ×1
windows ×1