本文将介绍PostgreSQL8.2中的嵌套事务?的详细情况,。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于c#中的PostgresqlNpgsql.Pos
本文将介绍PostgreSQL 8.2中的嵌套事务?的详细情况,。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于c#中的Postgresql Npgsql.PostgresException、centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教、PHP和PostgreSQL事务?、postgresql – clojure.java.jdbc中的嵌套事务的知识。
本文目录一览:- PostgreSQL 8.2中的嵌套事务?
- c#中的Postgresql Npgsql.PostgresException
- centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教
- PHP和PostgreSQL事务?
- postgresql – clojure.java.jdbc中的嵌套事务
PostgreSQL 8.2中的嵌套事务?
我正在研究应用数据库架构更新的脚本。我已经使用start transaction /
commit设置了所有的SQL更新脚本。我在命令行上将这些脚本传递给psql。
现在,我需要在一个事务中同时应用多个脚本。到目前为止,我想出的唯一解决方案是从原始脚本集中删除启动事务/提交,然后将它们卡在新的启动事务/提交块中。我正在编写perl脚本来即时执行此操作。
实际上,我想要嵌套事务,但是我无法弄清楚在postgresql中该如何做。
为此有什么方法可以进行或模拟嵌套事务?我设置了一些东西来自动解决任何错误,因此,如果任何较低的事务失败,我就不需要继续进行顶层事务。
c#中的Postgresql Npgsql.PostgresException
public void connectDB() { try { server = "localhost"; database = "DoveVer3"; uid = "admin"; password = "admin"; string connectionString; connectionString = "Host=" + server + ";Username =" + uid + ";" + "PASSWORD=" + password + ";DATABASE=" + database; connection.ConnectionString = connectionString; connection.open(); } catch (Exception e) { MessageBox.Show(e.Message); } }
我在下面的代码中获得了Exeption:
public void AddDovetoDB(Dove dove) { //add new dove record to tableDB connectDB(); cmd = new NpgsqlCommand(); cmd.Connection = connection; cmd.CommandText = "SELECT * FROM " + DoveTableDB + " WHERE `" + DoveIdColumnDoveTable + "` = '" + dove.GetDoveId() + "'"; NpgsqlDataReader rdr = cmd.ExecuteReader(); //// <<<<< HERE if (rdr.Read() != true) { rdr.Close(); cmd.Parameters.Clear(); cmd.CommandText = "INSERT INTO " + DoveTableDB + "(" + DoveIdColumnDoveTable + "," + DoveIdFatherColumnDoveTable + "," + DoveIdMotherColumnDoveTable + "," + DoveEyesColorColumnDoveTable + "," + DoveFeatherColorDoveTable + "," + DoveImageNameColumnDoveTable + "," + DoveSexColumnDoveTable +") VALUES ('" + dove.GetDoveId() + "','" + dove.GetDoveFatherId() + "','" + dove.GetDoveMotherId() + "','" + dove.GetEyesColor() + "','" + dove.GetFeathersColor()+ "','" + dove.GetimageName() + "','" + dove.GetSex()+ "')"; cmd.ExecuteNonQuery(); } connection.Close(); }
我的数据库名为DoveVer3,我的架构DoveSchema在这里是我的表代码:
Name: DoveTable; Type: TABLE; Schema: DoveSchema; Owner: admin -- CREATE TABLE "DoveTable" ( "doveId" character varying(20)[] NOT NULL,"doveFather" character varying(20)[],"doveMother" character varying,"doveEyesColor" character varying(20)[],"doveFeathersColor" character varying(20)[],"doveSex" smallint DEFAULT 3 NOT NULL,"imageName" character varying(30) ); ALTER TABLE "DoveTable" OWNER TO admin;
例外基础信息:
relation “dovetable” don’t exist; Statemants: {SELECT * FROM DoveTable
WHEREdoveId
= ‘Test’}
解决方法
SELECT * FROM "DoveTable"
请注意,它用双引号括起来,’D’和’T’都是大写的.使用带引号的标识符时,必须始终按照定义它们的方式将它们写出来.
centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教
1. 下载源码
$ mkdir /usr/downloads $ wget -c http://cn2.php.net/distributions/php-5.6.20.tar.gz $ tar -xvf php-5.6.20.tar.gz $ mv php-5.6.20 /usr/local/src $ cd !$ & cd php-5.6.20
2. 阅读安装指导
$ ls -also $ less README $ less INSTALL
3. 安装依赖包
$ yum install apr apr-util apr-devel apr-util-devel prce lynx
4. 安装httpd
$ wget -c http://apache.fayea.com//httpd/httpd-2.4.20.tar.gz $ tar -xvf httpd-2.4.20.tar.gz $ cd httpd-2.4.20 $ ./configure \ --prefix=/usr/local/programs/apache2 \ --enable-rewrite \ --enable-so \ --enable-headers \ --enable-expires \ --with-mpm=worker \ --enable-modules=most \ --enable-deflate \ --enable-module=shared $ make $ make install $ cd /usr/local/programs/apache2 $ cp bin/apachectl /etc/init.d/httpd ## 复制启动脚本 $ /etc/init.d/httpd start ## 启动apache服务器,访问http://localhost/ $ egrep -v ''^[ ]*#|^$'' /usr/local/apache2/conf/httpd.conf | nl ## 查看apache服务器的配置 ## 将apache加入系统服务 vi /etc/rc.d/rc.local ``` /usr/local/programs/apache2/bin/apachectl start ``` $ cat /etc/rc.local
4. 安装postgresql
立即学习“PHP免费学习笔记(深入)”;
$ yum install readline-devel ## 安装readline依赖 $ cd /usr/downloads $ wget -c https://ftp.postgresql.org/pub/source/v9.5.0/postgresql-9.5.0.tar.bz2 $ tar -xvf postgresql-9.5.0.tar.bz2 $ cd postgresql-9.5.0 $ ./configure --prefix=/usr/local/programs/postgresql $ make $ su $ make install $ /sbin/ldconfig /usr/local/programs/postgresql/lib ## 刷新下共享动态库 $ cd /usr/local/programs/postgresql $ bin/psql --version ## 检查运行情况 ## 开始对postgresql的配置 $ vi /etc/profile.d/postgresql.sh ## 增加环境变量,不推荐直接在/etc/profile中添加,系统更新升级时会需要merge ``` PATH=/usr/local/programs/postgresql:$PATH export PATH ``` $ source /etc/profile ## 更新环境变量 ## 增加用户和其他文件夹 $ adduser postgres $ passwd postgres $ mkdir /usr/local/programs/postgresql/logs $ mkdir /usr/local/programs/postgresql/data $ chown postgres /usr/local/programs/postgresql/data $ su - postgres ## 初始化数据库 $ ./bin/initdb -D ./data $ ./bin/createdb test $ ./bin/psql test ## 已有数据库,可导入data文件夹后尝试root访问,假如带密码,可能需要进一步研究下 $ ./bin/postgres -D ./data >./logs/start-log-1.log 2>&1 & $ ./bin/psql --list ##列出数据库 ## ok,安装完成 ## 自定义设置,权限控制等,可以跳过,等熟悉使用后再做 ## 编辑数据库配置及权限文件: $ vi /usr/local/programs/postgresql/data/postgresql.conf ## 数据库配置文件 $ chown postgres postgresql.conf $ chmod 644 postgresql.conf $ vi /usr/local/programs/postgresql/data/pg_hba.conf ## 权限文件 $ vi /usr/local/programs/postgresql/data/pg_ident.conf ## 设置开机自启动: $ vi /etc/rc.d/rc.local ## 添加如下内容 ``` /usr/local/programs/postgresql/bin/postgresql start ```
5. 安装php
## 源码已经在第一步中下载,现在开始安装: $ yum install libxml2 libxml2-devel libpng libpng-devel libjpeg libjpeg-devel freetype freetype-devel $ ./configure \ --prefix=/usr/local/programs/php \ --with-apxs2=/usr/local/programs/apache2/bin/apxs \ --with-zlib \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --with-zlib-dir \ --enable-mbstring \ --with-pgsql=/usr/local/programs/postgresql \ --with-pdo-pgsql=/usr/local/programs/postgresql $ make $ make test > Bug #42718 (unsafe_raw filter not applied when configured as default filter) [ext/filter/tests/bug42718.phpt] XFAIL REASON: FILTER_UNSAFE_RAW not applied when configured as default filter, even with flags > Bug #67296 (filter_input doesn''t validate variables) [ext/filter/tests/bug49184.phpt] XFAIL REASON: See Bug #49184 > Bug #53640 (XBM images require width to be multiple of 8) [ext/gd/tests/bug53640.phpt] XFAIL REASON: Padding is not implemented yet > zend multibyte (7) [ext/mbstring/tests/zend_multibyte-07.phpt] XFAIL REASON: https://bugs.php.net/bug.php?id=66582 > zend multibyte (9) [ext/mbstring/tests/zend_multibyte-09.phpt] XFAIL REASON: https://bugs.php.net/bug.php?id=66582 >Bug #70470 (Built-in server truncates headers spanning over TCP packets) [sapi/cli/tests/bug70470.phpt] XFAIL REASON: bug is not fixed yet ## 查阅官方的bug,发现: > id=66582: status : Closed. Fixed in master (PHP7) > id=42718: status : Assigned > id=42718: reference to id=49184, unsolved for many years ## 那就不关心了,直接装吧 $ make install > You may want to add: /usr/local/programs/php/lib/php to your php.ini include_path ## 那就按它说的设置吧 $ cp php.ini-development /usr/local/programs/php/lib/php.ini ``` include_path = ".;/usr/local/programs/php/lib/php" ## 然后,编辑httpd的设置,确保其能正确解析php文件 ``` ... LoadModule php5_module modules/libphp5.so ... AddType application/x-httpd-php .php AddType application/x-httpd-php-source .php5 ... <ifmodule dir_module> DirectoryIndex index.html index.php </ifmodule> ``` ## 重启httpd,测试 $ cd /usr/local/programs/apache2 $ bin/httpd -h $ bin/httpd -k stop $ bin/httpd -f conf/httpd.conf ## 默认设置的www页面在./htdocs/下,那就先去里面建一个测试页面吧 $ vi htdocs/index.php ``` <?php phpinfo(); ?> ``` $ curl http://localhost/index.php |grep postgresql #ok
后续应该做的事
* 1. 启动时,不需要要手动指定配置文件
* 2. php初始化www目录设置
* 3. php 用户、权限管理等
以上就介绍了centos 7下源码编译安装php支持PostgreSQL,包括了postgresql,centos 7方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
PHP和PostgreSQL事务?
很久以前,我写了一个处理postgresql db连接的php类。
我已将事务添加到插入/更新功能中,对我来说很好用。但是最近我发现了有关“ pg_prepare”函数的信息。
我对该函数的功能以及是否最好切换到该函数感到困惑。
当前,每当我执行插入/更新时,我的sql如下所示:
$transactionSql = "PREPARE TRANSACTION ".md5(time()).";" .$theUpdateOrDeleteSQL.";". ."COMMIT;";This will return something like:PREPARE TRANSACTION ''4601a2e4b4aa2632167d3cc62b516e6d'';INSERT INTO users (username,g_id,email,password) VALUES(''test'', ''1'', ''test'',''1234'');COMMIT;
我已经使用关系构建了数据库,并且正在使用(如果可能):
ON DELETE CASCADE ON UPDATE CASCADE
但是我想100%确保数据库中的内容是干净的,如果/在更新/删除或插入失败时没有遗留物。
如果您可以分享您对pg_prepare的意见/经验,那会很好,我是否真的需要“准备交易”以及任何其他可能对我有帮助的事情?:)
答案1
不,您不需要准备事务(这是针对跨不同服务器的分布式事务的,正如Milen所指出的那样)。
我不确定PHP接口如何处理该问题,但是只要您可以确保未在自动提交模式下运行,就可以了。
如果您无法控制自动提交模式,只需将您的语句放入BEGIN … COMMIT块中
postgresql – clojure.java.jdbc中的嵌套事务
我们目前运行如下:
(jdbc/with-db-transaction [tx connection] (jdbc/query tx [(jdbc/prepare-statement (:connection tx) "select * from m1" {:fetch-size 1000})] {:result-set-fn (process! [tx result-set] ...)}))
过程!是
(defn process! [tx result-set] (jdbc/with-db-transaction [tx tx] (jdbc/insert-multi! tx :m2 [:m2_column] (mapv (fn [r] [(calculate r)]) result-set))))
select查询使用游标并且懒惰地使用.请参阅:clojure.java.jdbc lazy query.这就是它被包装在外部事务中的原因.
问题:
> Postgres是否存在数百万条记录的(嵌套)交易? clojure.java.jdbc docs说嵌套交易被外部交易所吸收,所以实际上我们只有一笔交易.它是否正确?
>如果我们想要为插入创建单独的事务,那么使用与数据库的不同连接的解决方案是什么?我们已经使用了连接池,所以可能已经是这种情况了?
解决方法
nested transactions are absorbed by the outer one
这是完全正确的.您可以查看sources:这是我们已经在交易时执行的分支;正如您所看到的,func(表示带有事务宏的主体的函数)只是在没有其他设置的情况下被调用.
is the solution to use a different connection to the database?
使用clojure.java.jdbc这似乎是唯一的选择.只需通过你的游泳池而不是tx来处理!功能.问题是这些事务不再嵌套,因此如果内部事务提交和外部由于某种原因而失败,则内部事务将不会回滚.您可以使用raw JDBC and savepoints实现“嵌套事务行为”.
今天关于PostgreSQL 8.2中的嵌套事务?的介绍到此结束,谢谢您的阅读,有关c#中的Postgresql Npgsql.PostgresException、centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教、PHP和PostgreSQL事务?、postgresql – clojure.java.jdbc中的嵌套事务等更多相关知识的信息可以在本站进行查询。
本文标签: