point in-time recovery in PostgreSQL for windows - postgresql

I am using archive_cleanup_command in my recovery.conf file. When I start PostgreSQL server I am getting FATAL and postgres is not starting.
FATAL: syntax error in file "recovery.conf" line 4, near token "'"
showing in pg_log
recovery.conf:
standby_mode = 'on'
primary_conninfo = 'host=localhost port=5432 user=postgres password=postgres'
restore_command = 'copy "D:\\Program Files\\WAL\\%f" "%p" '
archive_cleanup_command = 'pg_archivecleanup "D:\\Program Files\\WAL" %r'
trigger_file = 'standby.stop'
recovery_target_timeline='latest'

Related

Postgresql pg_profile getting error while creating snapshot

I am referring https://github.com/zubkov-andrei/pg_profile for generating awr like report.
Steps which I have followed are as below :
1) Enabled below parameters inside postgresql.conf (located inside D:\Program Files\PostgreSQL\9.6\data)
track_activities = on
track_counts = on
track_io_timing = on
track_functions = on
shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.max = 1000
pg_stat_statements.track = 'top'
pg_stat_statements.save = off
pg_profile.topn = 20
pg_profile.retention = 7
2) Manually copied all the file beginning with pg_profile to D:\Program Files\PostgreSQL\9.6\share\extension
3) From pgAdmin4 console executed below commands successfully
CREATE EXTENSION dblink;
CREATE EXTENSION pg_stat_statements;
CREATE EXTENSION pg_profile;
4) To see which node is already present I executed SELECT * from node_show();
which resulted in
node_name as local
connstr as dbname=postgres port=5432
enabled as true
5) To create a snapshot I executed SELECT * from snapshot('local');
but getting below error
ERROR: could not establish connection
DETAIL: fe_sendauth: no password supplied
CONTEXT: SQL statement "SELECT dblink_connect('node_connection',node_connstr)"
PL/pgSQL function snapshot(integer) line 38 at PERFORM
PL/pgSQL function snapshot(name) line 9 at RETURN
SQL state: 08001
Once I am able to generate multiple snapshot then I guess I should be able to generate report.
just use SELECT * from snapshot()
look at the code of the function. It calls the other one with node as parameter.

Connecting to PostgreSQL in wsgi file

I ran into a 500 server error when trying to connect to PostgreSQL from wsgi file using psycopg2.
import psycopg2
def application(environ, start_response):
try:
conn = psycopg2.connect("database = testdb, user = postgres, password = secret")
execept:
print "I am unable to connect to the database"
status = '200 OK'
output = 'Hello Udacity, Robert!'
response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
After the creation of a database ('udacity' in my case), a table ('hello' in my case) and the population ('Hello world' in my case):
# psql environment
CREATE DATABASE udacity;
CREATE TABLE hello(
word text);
INSERT INTO hello VALUES ('Hello world');
You have to install python dependencies:
# shell environment
sudo apt install python-psycopg2 libpq-dev
sudo apt install python-pip
pip install psycopg2
Then, the next myapp.wsgi script works for me:
import psycopg2
def application(environ, start_response):
status = '200 OK'
output = 'Original message'
response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))]
start_response(status, response_headers)
# DB connection
try:
connection = psycopg2.connect("dbname='udacity' user='ubuntu' host='localhost' password='udacity'")
cursor = connection.cursor()
cursor.execute("""SELECT * from hello""")
rows = cursor.fetchall()
for row in rows:
output = row[0]
except:
output = 'E: Python script'
return [output]

PgBouncer and auth to PostgreSQL

pgbouncer version 1.7.2
psql (9.5.6)
I try use auth_hba_file (/var/lib/pgsql/9.5/data/pg_hba.conf) in PgBouncer.
Config pgbouncer.ini
postgres = host=localhost port=5432 dbname=postgres user=postgres
test = host=localhost port=5432 dbname=test user=test
[pgbouncer]
logfile = /var/log/pgbouncer/pgbouncer.log
pidfile = /var/run/pgbouncer/pgbouncer.pid
listen_addr = *
listen_port = 6432
auth_type = hba
auth_hba_file = /var/lib/pgsql/9.5/data/pg_hba.conf
admin_users = postgres
stats_users = stats, postgres
pool_mode = session
server_reset_query = DISCARD ALL
max_client_conn = 100
default_pool_size = 20
cat pg_hba.conf | grep -v "#" | grep -v "^$"
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
host test test 10.255.4.0/24 md5
psql -h 10.233.4.16 -p 5432 -U test
Password for user test:
psql (9.5.6)
Type "help" for help.
test=> \q
psql -h 10.233.4.16 -p 6432 -U test
psql: ERROR: No such user: test
tail -fn10 /var/log/pgbouncer/pgbouncer.log
LOG C-0x78f7e0: (nodb)/(nouser)#10.255.4.245:8963 closing because: No such user: test (age=0)
WARNING C-0x78f7e0: (nodb)/(nouser)#10.255.4.245:8963 Pooler Error: No such user: test
LOG C-0x78f7e0: (nodb)/(nouser)#10.255.4.245:8963 login failed: db=test user=test
But i cannot connect to postgresql (using PgBouncer) using pg_hba.conf
Can somebody help?
May you have example for use auth_hba_file.
Thanks
I changed config:
[root#dev-metrics2 pgbouncer]# cat pgbouncer.ini | grep -v ";" | grep -v "^$" | grep -v "#"
[databases]
postgres = host=localhost port=5432 dbname=postgres user=postgres
test = host=localhost port=5432 dbname=test auth_user=test
[pgbouncer]
logfile = /var/log/pgbouncer/pgbouncer.log
pidfile = /var/run/pgbouncer/pgbouncer.pid
listen_addr = *
listen_port = 6432
auth_query = SELECT usename, passwd FROM pg_shadow WHERE usename=$1
admin_users = postgres
stats_users = stats, postgres
pool_mode = session
server_reset_query = DISCARD ALL
max_client_conn = 100
default_pool_size = 20
Drop and Create user and DB
[local]:5432 postgres#postgres # DROP DATABASE test;
DROP DATABASE
[local]:5432 postgres#postgres # DROP USER test ;
DROP ROLE
[local]:5432 postgres#postgres # CREATE USER test with password 'test';
CREATE ROLE
[local]:5432 postgres#postgres # CREATE DATABASE test with owner test;
CREATE DATABASE
PGPASSWORD=test psql -h 10.233.4.16 -p 6432 -U test
Password for user test:
psql: ERROR: Auth failed
tail -fn1 /var/log/pgbouncer/pgbouncer.log
LOG Stats: 0 req/s, in 0 b/s, out 0 b/s,query 0 us
LOG C-0x17b57a0: test/test#10.255.4.245:3069 login attempt: db=test user=test tls=no
LOG C-0x17b57a0: test/test#10.255.4.245:3069 closing because: client unexpected eof (age=0)
LOG C-0x17b57a0: test/test#10.255.4.245:3070 login attempt: db=test user=test tls=no
LOG C-0x17b57a0: test/test#10.255.4.245:3070 closing because: Auth failed (age=0)
WARNING C-0x17b57a0: test/test#10.255.4.245:3070 Pooler Error: Auth failed
Work config:
cat pgbouncer.ini | grep -v ";" | grep -v "^$" | grep -v "#"
[databases]
*= port=5432 auth_user=postgres
[pgbouncer]
logfile = /var/log/pgbouncer/pgbouncer.log
pidfile = /var/run/pgbouncer/pgbouncer.pid
listen_addr = *
listen_port = 6432
auth_query = SELECT usename, passwd FROM pg_shadow WHERE usename=$1
admin_users = postgres
stats_users = stats, postgres
pool_mode = session
server_reset_query = DISCARD ALL
max_client_conn = 100
default_pool_size = 20
Try put space
*= port=5432 auth_user=postgres # old string
* = port=5432 auth_user=postgres # new string
work for me

Slony-i replication on Postgre 9.3/slony 2.2.0/window 7

Title : slony-i replication not working.
binary paths : C:\Program Files\PostgreSQL\9.3\share
Master.txt
cluster name = testing;
node 1 admin conninfo = 'dbname=original host=localhost user=postgres password=sa';
node 2 admin conninfo = 'dbname=copy host=localhost user=postgres password=sa';
init cluster (id = 1,comment = 'Node 1 - Master');
create set (id = 1, origin = 1);
set add table (set id = 1,origin = 1,id = 1 , full qualified name = 'public.test');
store node(id = 2,event node = 1,comment = 'slave');
store path(server = 1,client = 2,conninfo = 'dbname=original host=localhost user=postgres password=sa');
store path(server = 2,client = 1,conninfo = 'dbname=copy host=localhost user=postgres password=sa');
Slave.txt
CLUSTER NAME = testing;
node 1 admin conninfo = 'dbname=original host=localhost port=5432 user=postgres password=sa';
node 2 admin conninfo = 'dbname=copy host=localhost port=5432 user=postgres password=sa';
subscribe set (id = 1,provider = 1, receiver = 2, forward = no);
error
Question
keeping waiting for event and when i tested replication not working even slony replication appear.
thanks you
You need to create a slony service on both master and slave machine.
create a file and name it slon.conf with content:
cluster_name=testing
conn_info = 'dbname = original host = localhost user = postgres password = sa port = 5432'
Then, go to command prompt and head to the postgres bin folder and type:
slon -regservice Slony-I
slon -addengine Slony-I slon.conf
slon -listengines Slony-I
This must be done in both Master and slave machine

Why are long-running queries blank in postgresql log?

I'm running a log (log_min_duration_statement = 200) to analyse some slow queries in PostgreSQL 9.0 but the statements for worst queries aren't being logged. Is there any way I can find out what the queries actually are?
(some values replaced with *** for brevity and privacy.)
2012-06-29 02:10:39 UTC LOG: duration: 266.658 ms statement: SELECT *** FROM "oauth_accesstoken" WHERE "oauth_accesstoken"."token" = E'***'
2012-06-29 02:10:40 UTC LOG: duration: 1797.400 ms statement:
2012-06-29 02:10:49 UTC LOG: duration: 1670.132 ms statement:
2012-06-29 02:10:50 UTC LOG: duration: 354.336 ms statement: SELECT *** FROM ***
...
There are some log file destination options in postgresql.conf, as shown below. I suggest to use csvlog.
log_destination = 'csvlog'
logging_collector = on
log_directory = '/var/applog/pg_log/1922/'
log_rotation_age = 1d
log_rotation_size = 10MB
log_statement = 'ddl' # none, ddl, mod, all
log_min_duration_statement = 200
After making any changes, you need to reload the postgresql.conf file.
It turns out because I was keeping an eye on the logs with tail -f path | grep 'duration .+ ms' any statement starting with a newline was not visible. I was mainly doing this to highlight the duration string.