AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-4735

ThinkingMonkey's questions

Martin Hope
ThinkingMonkey
Asked: 2012-08-28 09:33:13 +0800 CST

PHP PDO(使用 libpq V 9.1.4)绑定以使用 CITEXT 的解决方法?

  • 0

场景

运行 PHP 和 PostgreSQL 的两个系统(不是服务器),版本如下

  • 软呢帽 15:

    PHP

    PHP 5.3.13 (cli) (built: May 9 2012 14:38:35)
    Copyright (c) 1997-2012 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    pdo_pgsql
    PostgreSQL(libpq) 版本9.0.7
    模块版本 1.0.2


    PostgreSQL

    PostgreSQL 9.1.4
    启用 CITEXT 扩展。

  • ArchLinux:

    PHP

    PHP 5.4.6 (cli) (built: Aug 16 2012 12:50:09)
    Copyright (c) 1997-2012 The PHP Group
    Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
    pdo_pgsql
    PostgreSQL(libpq) 版本9.1.4
    模块版本 1.0.2


    PostgreSQL

    PostgreSQL 9.1.4
    启用 CITEXT 扩展。


当一个简单的查询如

select column1 from schema1.table1 where column1= ? 

其中 column1 是 CITEXT 类型,通过 PHP PDO 执行

  • 在带有 PHP 5.3.13、libpq 9.0.7 的 Fedora 上,查询按预期执行 CITEXT(发生不区分大小写的搜索)。
  • 在带有 PHP 5.4.6、libpq 9.1.4 的 ArchLinux 上,使用 CITEXT 的查询没有按预期执行(发生区分大小写的搜索)。

我猜较新版本的 PHP PDO 库正在做类似的事情:

select column1 from schema1.table1 where column1= 'value'::text;

在绑定期间。

  • 我对吗?
  • 有解决方法吗?否则,在使用较新版本的 PDO 时,使用 CITEXT 作为列数据类型来获得不区分大小写搜索的优势是没有用的。

更新

开启语句级登录后,在 ArchLinux 上使用 PHP 5.4.6,libpq 9.1.4 :

LOG:  execute pdo_stmt_00000001: select column1 from schema1.table1 where column1 = $1
DETAIL:  parameters: $1 = 'value'
LOG:  statement: DEALLOCATE pdo_stmt_00000001

其中列的实际column1值为VALUE。

仍然返回 0 个元素。

当声明

select column1 from schema1.table1 where column1 = 'value';

直接在PSQL提示符下执行,返回单行。

 column1  
---------
  VALUE
 (1 row)

所以,类型转换不会发生!我仍然无法理解PDO/的行为postgresql。


更新 2012-08-27 16:15:43.669142+00 (UMT + 0)

在尝试直接执行查询而不准备语句之后。

这是用于测试的代码:

try {
    $db = new PDO('pgsql:dbname=database1;user=user;password=pass;host=localhost');
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "SELECT column1 from schema1.column1 where column1 = 'value'::citext ";
    $retval=$db->query($sql);
    foreach ($retval as $row) {
        print $row['uname'] . '<br>';
    }
}catch (PDOException $PDOerr) {
    echo 'An error occured : <br>';
    var_dump($PDOerr);
    exit;
    //some thing went wrong while performing the action on db.
    }

我得到错误:

object(PDOException)#10 (8) { ["message":protected]=> string(211) "SQLSTATE[42704]: \
Undefined object: 7 ERROR: type "citext" does not exist LINE 1: ...

我不明白为什么citext没有被检测到!当语句直接在PSQL提示符下执行时,一切正常,如上所述。

postgresql php
  • 1 个回答
  • 1867 Views
Martin Hope
ThinkingMonkey
Asked: 2012-08-15 04:12:48 +0800 CST

在 HDD 崩溃后启动 PostgreSQL 服务器导致 FAILED STATE

  • 10

我正在Fedora 15使用PostgreSQL 9.1.4. Fedora 最近崩溃了,之后:

尝试启动 PostgreSQL 服务器:

service postgresql-9.1 start

给

Starting postgresql-9.1 (via systemctl):  Job failed. See system logs and 'systemctl status' for details.
                                                       [FAILED]

虽然,当我在系统重启后第一次启动服务器时,服务器正常启动。
但是,尝试使用psql会出现此错误:

psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

.s.PGSQL.5432文件在系统上的任何地方都不存在。Alocate .s.PGSQL.5432什么也不输出。


系统日志有这个:

Aug 14 17:31:58 localhost systemd[1]: postgresql-9.1.service: control process exited, code=exited status=1
Aug 14 17:31:58 localhost systemd[1]: Unit postgresql-9.1.service entered failed state.

一个

systemctl status postgresql-9.1.service

给

postgresql-9.1.service - SYSV: PostgreSQL database server.
          Loaded: loaded (/etc/rc.d/init.d/postgresql-9.1)
      Active: failed since Tue, 14 Aug 2012 17:31:58 +0530; 58s ago
     Process: 2811 ExecStop=/etc/rc.d/init.d/postgresql-9.1 stop (code=exited, status=1/FAILURE)
     Process: 12423 ExecStart=/etc/rc.d/init.d/postgresql-9.1 start (code=exited, status=1/FAILURE)
    Main PID: 2551 (code=exited, status=1/FAILURE)
      CGroup: name=systemd:/system/postgresql-9.1.service

我没有更改 fsync 的默认设置,所以我猜,它设置为on. 我在硬盘上。硬盘坏了。

硬盘崩溃

HDD 崩溃导致在fsck提示符下运行手册,而不是基于 gui。用它修复大量的 inode 等。之后我用Ctrl++Alt重新启动了系统Delete。

PostgreSQL 的日志是这样的:

LOG:  database system was interrupted; last known up at 2012-08-14 17:31:57 IST
LOG:  database system was not properly shut down; automatic recovery in progress
LOG:  record with zero length at 0/41A4E58
LOG:  redo is not required
FATAL:  could not access status of transaction 1
DETAIL:  Could not open file "pg_multixact/offsets/0000": No such file or directory.
LOG:  startup process (PID 13016) exited with exit code 1
LOG:  aborting startup due to startup process failure

更新

在获取目录的文件系统级别副本后尝试启动服务器/var/lib/pgsql,并运行./pg_resetxlog -f /var/lib/pgsql/9.1/data/结果xlog -f /var/lib/pgsql/9.1/data/仍然会产生:

LOG:  database system was interrupted; last known up at 2012-08-14 18:46:36 IST
LOG:  database system was not properly shut down; automatic recovery in progress
LOG:  record with zero length at 0/6000078
LOG:  redo is not required
FATAL:  could not access status of transaction 1
DETAIL:  Could not open file "pg_multixact/offsets/0000": No such file or directory.
LOG:  startup process (PID 13766) exited with exit code 1
LOG:  aborting startup due to startup process failure
postgresql linux
  • 1 个回答
  • 13961 Views
Martin Hope
ThinkingMonkey
Asked: 2012-08-05 23:44:44 +0800 CST

postgresql initdb 出了什么问题?为什么“UTF-8”编码没有得到强制执行?

  • 0

我正在使用 PostgreSQL 9.1。尝试默认强制执行 UTF8 编码。

这就是我正在做的事情。

service postgresql initdb -E 'UTF-8' \
               --lc-collate='en_US.UTF-8' \
               --lc-ctype=locale='en_US.UTF-8';

虽然初始化过程没有任何问题,

a\l在psql提示符处提供了详细信息。

                             List of databases
   Name    | Owner    |Encoding  | Collate | Ctype |   Access privileges   
-----------+----------+----------+---------+-------+-----------------------
 postgres  | postgres | LATIN1   | en_US   | en_US | 

为什么UTF-8编码没有得到强制执行?

postgresql
  • 1 个回答
  • 7288 Views
Martin Hope
ThinkingMonkey
Asked: 2012-08-01 07:10:17 +0800 CST

PostgreSQL:这是因为锁(行级别)吗?

  • 2

我有一张大约有 210 万个元组的表。其中有纬度和经度列。我正在尝试将其转换为地理类型(带有 SRID 的点)。

我写的函数(过程)在我限制条目时工作正常(比如 : SELECT id,longitude,latitude FROM list_of_location limit 50)。

CREATE OR REPLACE FUNCTION convertlatlon() RETURNS VOID AS $$
DECLARE rec RECORD;
BEGIN
    FOR rec IN SELECT id,longitude,latitude FROM list_of_location
    LOOP
    UPDATE list_of_location SET location= concat('SRID=4326;POINT(',rec.longitude,' ',rec.latitude,')') WHERE id=rec.id;    
    END LOOP;
END;
$$ LANGUAGE 'plpgsql' ;

  • 当我尝试在整个表上运行它时,PostgreSQL 似乎什么都不做。已经等了一个半小时。
  • 在其运行的核心上消耗 99% 的 CPU。
  • 不会启动任何其他 PostgreSQL 实例来利用其他核心(因为请求来自单个用户?)。
  • 这是因为锁(行级别)吗?
  • 如何规避这个?
postgresql spatial
  • 2 个回答
  • 346 Views
Martin Hope
ThinkingMonkey
Asked: 2012-04-25 10:25:15 +0800 CST

打开和关闭数据库连接的成本是多少?

  • 17

CPU 密集型如何在 MySQL 中打开和关闭数据库连接(对于 Web 应用程序)

  • ...当数据库软件在本地主机上时?
  • ...当数据库软件在另一台机器上时?
mysql database-design
  • 4 个回答
  • 22651 Views
Martin Hope
ThinkingMonkey
Asked: 2011-12-05 13:14:29 +0800 CST

什么是QP层?

  • 1

来自blogs.innodb.com:具有 Binlog 功能的 InnoDB Memcached

在我们早期的实验室版本中,我们通过 InnoDB Memcached Daemon 插件展示了一个 MySQL NoSQL 解决方案(参见之前的 Calvin 和我的帖子)。较早的版本允许 Memcached 插件直接与 InnoDB 交互,完全绕过 MySQL 优化器和QP layers. 它与另一个流行的 MySQL NoSQL 解决方案 HandlerSocket 不同,它甚至跳过 Handler API 层并直接通过 InnoDB API 访问 InnoDB。因此,理论上,它会更简单、更有效。

什么是QP 图层?

搜索没有给我带来任何好的结果。我最接近的是Query Path。这是正确的吗?

mysql query
  • 1 个回答
  • 257 Views
Martin Hope
ThinkingMonkey
Asked: 2011-11-29 05:45:21 +0800 CST

Webapp & MySQL:行级安全

  • 8

我正在尝试在使用 MySQL 开发的 webapp 上模拟行级安全性。

使用此方法:使用所需的表创建一个数据库,其中将存储与所有用户相关的数据,并对表的列进行适当的索引。

根据用户 ID 为特定用户创建 mysql“视图”。

为了实现行级安全性,我还必须为每个用户创建 mysql 帐户并设置视图的“授予”权限。

对于 Web 界面,将使用基于 PHP 的 MVC 框架。

但是,根据我的研究:

1] Having separate mysql account per user "make the webapp less secure".
2]Having separate mysql account per user "increases the disk I/O".

问题:
1] How does creating mysql user per webapp user make the webapp less secure?
2] Does the disk I/O increase considerably?
3] Is there a better way to implement row-level-security in MySQL?
4]What are the pros/cons of implementing row-level-security by the above method?

为什么我要查看行级安全性?
I need row level security because there are rows which will be shared between multiple users & have 1 or 2 owners to it. Only these owners can delete/modify them.

我无法添加诸如“行级安全”“磁盘 io”之类的标签,因为我的声誉点较少。如果其他人可以,请这样做。

mysql database-design
  • 1 个回答
  • 1899 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve