postgresql

Handling race conditions in PostgreSQL

末鹿安然 提交于 2020-12-29 03:47:52
问题 I have several workers, each holding its own connection to PostgreSQL. The workers manipulate with different tables. The workers handle parallel requests from outside the system. One of the tables being accessed is the table of users. When some information comes, I first need to ensure there is a record for the user in the table. If there is no record, I wish to create one at first. I'm using the following idiom: if [user does not exist] then [create user] The code of [user does not exist] is

django连接mysql配置方法

房东的猫 提交于 2020-12-29 03:24:46
转载地址:https://blog.csdn.net/it_dream_er/article/details/52092262 最近在学习django,学到第五章模型时,需要连接数据库,然后,在这里分享一下方法。 起初是不知道怎样配置mysql数据库,但是还好,django的官网上面有相关的配置方法,下面就直接给分享一下。 这是settings文件里面的基础配置,使用的是sqlite,那我们需要连接其他数据库呢? DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'mydatabase', } } 下面是mysql的配置方法: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'mydatabase', 'USER': 'mydatabaseuser', 'PASSWORD': 'mypassword', 'HOST': '127.0.0.1', 'PORT': '3306', } } 下面解释一下,里面参数的意思: ENGINE : 指定数据库驱动,不同的数据库这个字段不同,下面是常见的集中数据库的ENGINE的写法: django .db .backends .postgresql #

sql查询更新update select

非 Y 不嫁゛ 提交于 2020-12-28 01:01:34
针对一个上线的项目进行数据库优化,以便后期统计,遇到一个数据填充的问题,在此记录一下,各位如果也有这种问题,欢迎一起交流。 表结构: 当我从其它数据源使用sql来填充这个表数据时,from_id都是null,因此要使用update来对from_id进行补充。 update t_ch_test t set t.from_id = (select max(a.id) from t_ch_test a where a.node_id = t.node_id and a.id < t.id) 使用update select来自连接进行更新操作。这个sql在oracle中执行是没有任何问题的,然后,坑爹的是,这个sql在postgresql中编译都报错。而我们项目组用的最多的就是postgresql,因此无语了。 后来百度一下,发现postgresql在update时不支持表别名alis,所以最开始想的是把别名去掉,如下: update t_ch_test set from_id = (select max(a.id) from t_ch_test a where a.node_id = node_id and a.id < id) sql执行是没有问题了,但一查结果,发现from_id全部为null,怎么回事儿呢。 后来在同事的指导下,a.id < id换成了a.id < 100,执行成功

How Do I Backup My PostgreSQL Database with Cron?

*爱你&永不变心* 提交于 2020-12-27 07:46:26
问题 I can run commands like vacuumdb, pg_dump, and psql just fine in a script if I preface them like so: /usr/bin/sudo -u postgres /usr/bin/pg_dump -Fc mydatabase > /opt/postgresql/prevac.gz /usr/bin/sudo -u postgres /usr/bin/vacuumdb --analyze mydatabase /usr/bin/sudo -u postgres /usr/bin/pg_dump -Fc mydatabase > /opt/postgresql/postvac.gz SCHEMA_BACKUP="/opt/postgresql/$(date +%w).db.schema" sudo -u postgres /usr/bin/pg_dump -C -s mydatabase > $SCHEMA_BACKUP These run at command line on Redhat

How Do I Backup My PostgreSQL Database with Cron?

两盒软妹~` 提交于 2020-12-27 07:46:13
问题 I can run commands like vacuumdb, pg_dump, and psql just fine in a script if I preface them like so: /usr/bin/sudo -u postgres /usr/bin/pg_dump -Fc mydatabase > /opt/postgresql/prevac.gz /usr/bin/sudo -u postgres /usr/bin/vacuumdb --analyze mydatabase /usr/bin/sudo -u postgres /usr/bin/pg_dump -Fc mydatabase > /opt/postgresql/postvac.gz SCHEMA_BACKUP="/opt/postgresql/$(date +%w).db.schema" sudo -u postgres /usr/bin/pg_dump -C -s mydatabase > $SCHEMA_BACKUP These run at command line on Redhat

服务器(Linux)缓冲跟踪类型的系统调用分析

走远了吗. 提交于 2020-12-26 16:57:11
本文主要讲解缓冲跟踪型的系统调用分析,主要目的是为了探究和分析CPU在内核或与用户空间结合部分的系统调用细节,从中可以发现一些问题,用于性能或者其他问题研究。 首先是两个概念: 断点跟踪类型,其是在进行取样时,中断目标程序的执行来获取数据的,比如strace命令。 缓冲跟踪类型,这就和断点跟踪不一样了,它是可以将获取到的检测数据缓存在内核里,而目标程序可以不中断执行。dtrace命令就属于缓冲跟踪。 系统调用有很多,Linux操作系统可能就有几百个(具体没有统计)。 案例1: 我们以进程间通信相关的一个系统调用kill为例来检测系统中的具体情况。命令如下: sudo dtrace -qn 'syscall::kill:entry { printf("%Y: %s (PID %d) sent a SIG %d to PID %d\n",walltimestamp,execname,pid,arg1,arg0);}' 执行结果如下,其中PID=1位init进程,它是所有其他用户进程的祖先进程,并且会监视其他进程。 我们来分析下第一行:init 进程发送了一个SIG信号 15 到PID -13929,其中SIG 15 是指SIGTERM 信号 案例2: 我们可以利用dtrace命令对Postgres数据库进程进行系统调用分析。 命令: sudo dtrace -n 'syscall::

postgres rename database not working

瘦欲@ 提交于 2020-12-26 12:14:43
问题 bin]# ./createdb cx123 -U postgres [bin]# ./createdb cx111 -U postgres [bin]# ./psql -d cx123 -U postgres Welcome to psql 8.3.7, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit cx123=# ALTER DATABASE cx111 RENAME TO cx222 cx123-# \q [bin]# ./psql -l -U postgres List of databases Name | Owner | Encoding -----------+----------+---------- cx111 |

postgres rename database not working

梦想的初衷 提交于 2020-12-26 12:14:20
问题 bin]# ./createdb cx123 -U postgres [bin]# ./createdb cx111 -U postgres [bin]# ./psql -d cx123 -U postgres Welcome to psql 8.3.7, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit cx123=# ALTER DATABASE cx111 RENAME TO cx222 cx123-# \q [bin]# ./psql -l -U postgres List of databases Name | Owner | Encoding -----------+----------+---------- cx111 |

Entity Framework Core Many to Many change navigation property names

亡梦爱人 提交于 2020-12-26 10:23:21
问题 I have a table called "LogBookSystemUsers" and I want to setup many to many functionality in EF Core 5. I almost have it working but the problem is my ID columns are named SystemUserId and LogBookId but when EF does the join it tries to use SystemUserID and LogBookID . This is my current configuration code: modelBuilder.Entity<SystemUser>() .HasMany(x => x.LogBooks) .WithMany(x => x.SystemUsers) .UsingEntity(x => { x.ToTable("LogBookSystemUsers", "LogBooks"); }); I tried this: modelBuilder

Entity Framework Core Many to Many change navigation property names

若如初见. 提交于 2020-12-26 10:22:48
问题 I have a table called "LogBookSystemUsers" and I want to setup many to many functionality in EF Core 5. I almost have it working but the problem is my ID columns are named SystemUserId and LogBookId but when EF does the join it tries to use SystemUserID and LogBookID . This is my current configuration code: modelBuilder.Entity<SystemUser>() .HasMany(x => x.LogBooks) .WithMany(x => x.SystemUsers) .UsingEntity(x => { x.ToTable("LogBookSystemUsers", "LogBooks"); }); I tried this: modelBuilder