psycopg

How can I pool connections using psycopg and gevent?

风格不统一 提交于 2019-12-18 11:33:39
问题 The psycopg docs state: "Psycopg connections are not green thread safe and can’t be used concurrently by different green threads. Trying to execute more than one command at time using one cursor per thread will result in an error (or a deadlock on versions before 2.4.2). Therefore, programmers are advised to either avoid sharing connections between coroutines or to use a library-friendly lock to synchronize shared connections, e.g. for pooling." I can't find an implementation of pool that is

Psycopg2 under osx works on commandline but fails in Aptana studio

末鹿安然 提交于 2019-12-11 15:40:02
问题 I have been developing under Python/Snowleopard happily for the part 6 months. I just upgraded Python to 2.6.5 and a whole bunch of libraries, including psycopg2 and Turbogears. I can start up tg-admin and run some queries with no problems. Similarly, I can run my web site from the command line with no problems. However, if I try to start my application under Aptana Studio, I get the following exception while trying to import psychopg2: ('dlopen(/Library/Frameworks/Python.framework/Versions/2

copy dataframe to postgres table with column that has defalut value

允我心安 提交于 2019-12-11 07:30:00
问题 I have the following postgreSql table stock , there the structure is following with column insert_time has a default value now() | column | pk | type | +-------------+-----+-----------+ | id | yes | int | | type | yes | enum | | c_date | | date | | qty | | int | | insert_time | | timestamp | I was trying to copy the followning df | id | type | date | qty | +-----+------+------------+------+ | 001 | CB04 | 2015-01-01 | 700 | | 155 | AB01 | 2015-01-01 | 500 | | 300 | AB01 | 2015-01-01 | 1500 |

psycopg2 error: DatabaseError: error with no message from the libpq

扶醉桌前 提交于 2019-12-08 15:20:36
问题 I have an application that parses and loads data from csv files into a Postgres 9.3 database. In serial execution insert statements/cursor executions work without an issue. I added celery in the mix to add parallel parsing and inserting of the data files. Parsing works fine. However, I go to run insert statements and I get: [2015-05-13 11:30:16,464: ERROR/Worker-1] ingest_task.work_it: Exception Traceback (most recent call last): File "ingest_tasks.py", line 86, in work_it rowcount = ingest

brew services

走远了吗. 提交于 2019-12-05 20:01:20
mysql brew services start mysql /Users/huoyinghui/workspaces/py2/lib/python2.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>. """) 来源: https://my.oschina.net/tplinuxhyh/blog/3134458

How do I know if I have successfully created a table (Python, Psycopg2)?

ぐ巨炮叔叔 提交于 2019-12-04 21:21:35
问题 I've looked at the documentations but haven't found anything that lets me know if the last command i've execute via cursor.execute("...") is successful. I'm expecting a reply like "1 row affected." 回答1: I'd expect some kind of exception to be risen. If everything went ok – the error code is 00000 and no exception will get risen. In create table case, you can always double check: try: cur.execute("SELECT ouch FROM aargh;") except Exception, e: pass errorcodes.lookup(e.pgcode[:2]) # 'CLASS

psycopg2 + pgbouncer. Async mode with gevent error

China☆狼群 提交于 2019-12-04 18:05:38
I've got an application psycopg2 + pgbouncer + gevent. Asynchronous application, ie one process serves multiple requests. Asynchronous access to database appeared in the latest version of psycopg2, if rather then 2.2. But just in this release introduces bug for which there is a lot of disconnections from pgbouncer. In the pgbouncer logs there are entries: 2011-10-04 12:16:38.972 4590 LOG C-0x1b3f490: database/user@10.58.65.143:43849 login successful: db=database user=user 2011-10-04 12:16:38.972 4590 LOG C-0x1b3f0a0: database/user@10.58.65.143:43850 login successful: db=database user=user 2011

Python-PostgreSQL psycopg2 interface --> executemany

廉价感情. 提交于 2019-12-03 14:46:34
I am currently analyzing a wikipedia dump file; I am extracting a bunch of data from it using python and persisting it into a PostgreSQL db. I am always trying to make things go faster for this file is huge (18GB). In order to interface with PostgreSQL, I am using psycopg2, but this module seems to mimic many other such DBAPIs. Anyway, I have a question concerning cursor.executemany(command, values); it seems to me like executing an executemany once every 1000 values or so is better than calling cursor.execute(command % value) for each of these 5 million values (please confirm or correct me!).

Ubuntu14.04 系统下Django配置使用Postgresql数据库配置

人盡茶涼 提交于 2019-12-02 16:41:48
下面是简略的配置,重点是Django配置Postgresql,因为Django使用pq需要psycopg2,重点是模块psycopg2的依赖模块! 一、更新系统 sudo aptitude install update sudo aptitude install upgrade 二、安装pip安装环境 sudo aptitude install python-pip 三、安装django sudo pip install django==1.8 四、安装Postgresql数据库 sudo aptitude install postgresql-9.3 五、安装psycopg2 1.安装环境依赖 sudo aptitude install python-dev libpq-dev 2.安装模块 sudo pip install psycopg2 六、配置Postgresql psql# create user abc with 'abc'; #新建用户abc,密码abc psql# create database abc owner abc; #新建数据库及其属主 abc 修改配置权限,否则无法初始化PG(本文最后一步) sudo vim /etc/postgresql/9.3/main/pg_hba.conf 将85,90,92行行末的peer和MD5,修改为trust(信任)

How can I pool connections using psycopg and gevent?

梦想与她 提交于 2019-11-30 03:23:59
The psycopg docs state: "Psycopg connections are not green thread safe and can’t be used concurrently by different green threads. Trying to execute more than one command at time using one cursor per thread will result in an error (or a deadlock on versions before 2.4.2). Therefore, programmers are advised to either avoid sharing connections between coroutines or to use a library-friendly lock to synchronize shared connections, e.g. for pooling." I can't find an implementation of pool that is green thread safe - are there any out there? I assume you know gevent-psycopg2 module, which makes