【问题标题】:Web2py Scheduler is creating "Idle in Transaction" process with PostgreSQLWeb2py Scheduler 正在使用 PostgreSQL 创建“Idle in Transaction”进程
【发布时间】:2018-10-25 09:53:14
【问题描述】:

这个问题是特定于 Web2py 框架中的调度程序的。

我将调度程序用作 Linux 服务。

我创建了一个文件 /etc/systemd/system/web2py-sched.service

[Unit]
Description=Web2Py scheduler service

[Service]
ExecStart=/usr/bin/python /home/www-data/web2py/web2py.py -K myApp
Type=simple
Restart=always
[Install]
WantedBy=multi-user.target

然后安装服务调用:

sudo systemctl enable /etc/systemd/system/web2py-sched.service 

systemctl start /etc/systemd/system/web2py-sched

当我检查我的 Postgres 状态时,我看到一些进程处于“Idle in Transaction”状态。

may@myApp:/home/www-data/web2py/scmyAppts$ sudo systemctl status postgresql@9.5-main
● postgresql@9.5-main.service - PostgreSQL Cluster 9.5-main
   Loaded: loaded (/lib/systemd/system/postgresql@.service; disabled; vendor preset: enabled)
   Active: active (running) since Tue 2018-10-16 15:39:25 PDT; 1 weeks 1 days ago
 Main PID: 28202 (postgres)
   CGroup: /system.slice/system-postgresql.slice/postgresql@9.5-main.service
           ├─10956 postgres: may mydb ::1(60654) idle in transaction                                                                           
           ├─10957 postgres: may mydb ::1(60656) idle in transaction                                                                           
           ├─13421 postgres: may mydb 10.5.77.35(51998) idle                                                                                   
           ├─13422 postgres: may mydb 10.5.77.35(52004) idle                                                                                   
           ├─13423 postgres: may postgres 10.5.77.35(52005) idle                                                                               
           ├─13425 postgres: may mydb 10.5.77.35(52007) idle                                                                                   
           ├─13433 postgres: may mydb 10.5.77.35(52332) idle                                                                                   
           ├─28202 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c config_file=/etc/postgresql/9.5/main/postgresql.conf
           ├─28204 postgres: checkpointer process                                                                                              
           ├─28205 postgres: writer process                                                                                                    
           ├─28206 postgres: wal writer process                                                                                                
           ├─28207 postgres: autovacuum launcher process                                                                                       
           ├─28208 postgres: stats collector process                                                                                           
           ├─30475 postgres: may mydb ::1(59838) idle                                                                                          
           ├─30476 postgres: may mydb ::1(59840) idle in transaction                                                                           
           └─30500 postgres: may mydb ::1(59842) idle

当我观察到少数进程处于空闲状态并且事务和我的数据库查询超时时,我检查了哪个表正在获取锁。

SELECT relation, pid, mode, granted, relname
FROM pg_locks
INNER JOIN pg_stat_user_tables
ON pg_locks.relation = pg_stat_user_tables.relid
WHERE pg_locks.pid='30476';

relation    pid    mode            granted   relname
16553      30476  AccessShareLock   TRUE    scheduler_task

请帮助我,我已经彻底检查了我的调度程序代码,并且在每次事务之后都会调用 db.commit()。

版本:

Version
2.17.2-stable+timestamp.2018.10.06.18.54.02
(Running on nginx/1.10.3, Python 2.7.12)

web2py is up to date

【问题讨论】:

    标签: postgresql scheduler web2py web2py-modules


    【解决方案1】:

    您的应用程序真的按照服务启动ExecStart=/usr/bin/python /home/www-data/web2py/web2py.py -K myApp 配置的那样称为“myApp”吗?

    您必须按名称指定您的应用程序。 'myapp' 只是一个占位符。

    最好的问候克莱门斯

    【讨论】:

    • 是的,只有它的 myApp :)。
    • 能否将您的应用程序(相关控制器和视图)的摘录发送给我,以便我可以将其导入我的环境中,这也是 web2py+nginx+postgres。因为我对调度程序没有任何问题。也许你的 uWSGI 问题也可以澄清 ;-)
    猜你喜欢
    • 2011-03-19
    • 1970-01-01
    • 2019-12-31
    • 1970-01-01
    • 2022-12-29
    • 1970-01-01
    • 1970-01-01
    • 2023-01-05
    • 1970-01-01
    相关资源
    最近更新 更多