/var/lib/gnumed/server/pycommon/x-test-psy.py is in gnumed-server 21.15-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | db = u'gnumed_v20' # a database configured "alter database %s set default_transaction_read_only to on"
user = 'gm-dbo' # a user with CREATE DATABASE powers
cmd_def_tx_ro = "SELECT upper(source), name, upper(setting) FROM pg_settings WHERE name = 'default_transaction_read_only'"
cmd_create_db = "create database %s_copy template %s" % (db, db)
import sys
import psycopg2
conn = psycopg2.connect(dbname = db, user = user)
print 'readonly:', conn.readonly
print 'autocommit:', conn.autocommit
conn.readonly = False
print 'readonly now:', conn.readonly
#curs = conn.cursor()
#curs.execute(cmd_def_tx_ro)
#print 'should show DEFAULT_TRANSACTION_READ_ONLY set to ON'
#print curs.fetchall()
#curs.close()
#conn.commit()
conn.autocommit = True
print 'readonly:', conn.readonly
print 'autocommit:', conn.autocommit
print 'the following CREATE DATABASE should fail'
curs = conn.cursor()
curs.execute(cmd_create_db)
curs.close()
conn.rollback()
conn.close()
sys.exit()
curs = conn.cursor()
#cmd_def_tx_ro = u'show default_transaction_read_only;'
cmd_def_tx_ro = "SELECT upper(source), name, upper(setting) FROM pg_settings WHERE name = 'default_transaction_read_only'"
cmd_tx_ro = u'show transaction_read_only;'
cmd_DEL = u'DELETE FROM dem.identity where pk is NULL'
print conn
print 'initial RO state:'
print ' psyco (conn.readonly):', conn.readonly
print ' psyco (conn.autocommit):', conn.autocommit
curs.execute(cmd_def_tx_ro)
print ' PG:', curs.fetchall(), u'- %s' % cmd_def_tx_ro
curs.execute(cmd_tx_ro)
print ' PG:', curs.fetchall(), u'- %s' % cmd_tx_ro
print ' running DELETE:', cmd_DEL
try:
curs.execute(cmd_DEL)
print ' success'
except Exception as e:
print ' failed:', e
conn.commit()
#print ''
print 'setting <conn.readonly = False> ...'
conn.readonly = False
print 'RO state in same TX:'
print ' psyco (conn.readonly):', conn.readonly
print ' psyco (conn.autocommit):', conn.autocommit
curs.execute(cmd_def_tx_ro)
print ' PG:', curs.fetchall(), u'- %s' % cmd_def_tx_ro
curs.execute(cmd_tx_ro)
print ' PG:', curs.fetchall(), u'- %s' % cmd_tx_ro
print ' running DELETE:', cmd_DEL
try:
curs.execute(cmd_DEL)
print ' success'
except Exception as e:
print ' failed:', e
conn.commit()
print 'RO state in next TX:'
print ' psyco (conn.readonly):', conn.readonly
print ' psyco (conn.autocommit):', conn.autocommit
curs.execute(cmd_def_tx_ro)
print ' PG:', curs.fetchall(), u'- %s' % cmd_def_tx_ro
curs.execute(cmd_tx_ro)
print ' PG:', curs.fetchall(), u'- %s' % cmd_tx_ro
print ' running DELETE:', cmd_DEL
try:
curs.execute(cmd_DEL)
print ' success'
except Exception as e:
print ' failed:', e
conn.commit()
print ''
print 'setting <conn.autocommit = True> (conn.readonly still False) ...'
print '-> means exiting psyco TX handling, needed for some DDL such as CREATE DATABASE ...'
conn.autocommit = True
print 'RO state in same TX:'
print ' psyco (conn.readonly):', conn.readonly
print ' psyco (conn.autocommit):', conn.autocommit
curs.execute(cmd_def_tx_ro)
print ' PG:', curs.fetchall(), u'- %s' % cmd_def_tx_ro
curs.execute(cmd_tx_ro)
print ' PG:', curs.fetchall(), u'- %s' % cmd_tx_ro
print ' running DELETE:', cmd_DEL
try:
curs.execute(cmd_DEL)
print ' success'
except Exception as e:
print ' failed:', e
conn.commit()
print 'RO state in next TX:'
print ' psyco (conn.readonly):', conn.readonly
print ' psyco (conn.autocommit):', conn.autocommit
curs.execute(cmd_def_tx_ro)
print ' PG:', curs.fetchall(), u'- %s' % cmd_def_tx_ro
curs.execute(cmd_tx_ro)
print ' PG:', curs.fetchall(), u'- %s' % cmd_tx_ro
print ' running DELETE:', cmd_DEL
try:
curs.execute(cmd_DEL)
print ' success'
except Exception as e:
print ' failed:', e
conn.commit()
print ''
print 'setting <conn.autocommit = False> (conn.readonly still False) ...'
print '-> means exiting psyco TX handling, needed for some DDL such as CREATE DATABASE ...'
conn.autocommit = False
print 'RO state in same TX:'
print ' psyco (conn.readonly):', conn.readonly
print ' psyco (conn.autocommit):', conn.autocommit
curs.execute(cmd_def_tx_ro)
print ' PG:', curs.fetchall(), u'- %s' % cmd_def_tx_ro
curs.execute(cmd_tx_ro)
print ' PG:', curs.fetchall(), u'- %s' % cmd_tx_ro
print ' running DELETE:', cmd_DEL
try:
curs.execute(cmd_DEL)
print ' success'
except Exception as e:
print ' failed:', e
conn.commit()
print 'RO state in same TX:'
print ' psyco (conn.readonly):', conn.readonly
print ' psyco (conn.autocommit):', conn.autocommit
curs.execute(cmd_def_tx_ro)
print ' PG:', curs.fetchall(), u'- %s' % cmd_def_tx_ro
curs.execute(cmd_tx_ro)
print ' PG:', curs.fetchall(), u'- %s' % cmd_tx_ro
print ' running DELETE:', cmd_DEL
try:
curs.execute(cmd_DEL)
print ' success'
except Exception as e:
print ' failed:', e
conn.commit()
sys.exit()
print 'RO state in same TX:'
print ' psyco - conn.readonly:', conn.readonly
print ' psyco - conn.autocommit:', conn.autocommit
curs.execute(cmd_def_tx_ro)
print ' PG - default_transaction_read_only:', curs.fetchall()
curs.execute(cmd_tx_ro)
print ' PG - transaction_read_only:', curs.fetchall()
conn.commit()
print 'RO state in next TX:'
print ' psyco - conn.readonly:', conn.readonly
curs.execute(cmd_def_tx_ro)
print ' PG - default_transaction_read_only:', curs.fetchall()
curs.execute(cmd_tx_ro)
print ' PG - transaction_read_only:', curs.fetchall()
conn.commit()
print ''
print 'PG/psyco split brain because of:'
cmd = "SELECT upper(source), name, upper(setting) FROM pg_settings WHERE name = 'default_transaction_read_only'"
print ' SQL:', cmd
curs.execute(cmd)
print ' PG:', curs.fetchall()
conn.commit()
curs.execute(u'DELETE FROM dem.identity where pk is NULL')
curs.close()
conn.commit()
conn.close()
|