Starting PgBouncer in Windows gives "FATAL could not open /dev/null" - windows

I have a practically vanilla install of PgBouncer on Windows Server 2019 Datacenter, downloaded using "Application Stack Builder". I'm trying to connect to a Postgres 11 database, local to the server.
The only config change I've done is to specify the database and the location of the log and PID files. Here's my config, taken from the Github pgbouncer-minimal.ini:
;;; This is an almost minimal starter configuration file that only
;;; contains the settings that are either mandatory or almost always
;;; useful. All settings show their default value.
[databases]
;; add yours here
postgres = host=localhost port=7450 user=postgres password=postgres
;; fallback
;* =
[pgbouncer]
;; required in daemon mode unless syslog is used
logfile = log/pgbouncer.log
;; required in daemon mode
pidfile = log/pgbouncer.pidfile
syslog = 0
;; set to enable TCP/IP connections
;listen_addr =
;; PgBouncer port
;listen_port = 6432
;; some systems prefer /var/run/postgresql
;unix_socket_dir = /tmp
;; change to taste
auth_type = trust
;; probably need this
auth_file = etc/userlist.txt
;; pool settings are perhaps best done per pool
;pool_mode = session
;default_pool_size = 20
;; should probably be raised for production
;max_client_conn = 100
Why do I keep getting the following error in the logs and how can I fix this?
2022-07-01 12:27:11.711 Coordinated Universal Time [8724] FATAL could not open /dev/null: The system cannot find the file specified.

Related

Changing MacOS Location based on SSID - check current location before changing

In this thread I received some assistance with getting this script to work correctly. The script essentially sets my network location according to the SSID I'm connected to. This is now working, however, it generates a lot of nuisance notifications.
Every time my laptop joins a wifi network, the script runs, sets the network location, and gives me a notification. Since power nap periodically joins the wifi to check for emails/updates and what have you, after a long weekend I'll get dozens of identical notifications.
How can I modify the script so that it only send a notification if the network location is changed to something different, not just when the script runs? Can I somehow check the existing network location and only change it/trigger a notification if the "new" location is different to the "existing" location?
Again, I'm extremely new to scripting on mac and GitHub in general; my previous experience is all on Windows and largely self taught.
Script:
#!/bin/bash
# automatically change configuration of Mac OS X based on location
# redirect all IO to a logfile
mkdir -p /usr/local/var/log
exec &>/usr/local/var/log/locationchanger.log
# get a little breather before we get data for things to settle down
sleep 2
# get SSID
SSID=$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | sed -n 's/^ *SSID: //p')
echo $(date) "New SSID found: $SSID"
# LOCATIONS
LOCATION=
Location_Automatic="Automatic"
Location_Office="Office"
Location_Site="Site"
# SSIDS
SSID_Office="My Office SSID"
SSID_Site="My Mobile SSID"
# SSID -> LOCATION mapping
case $SSID in
"$SSID_Office") LOCATION="$Location_Office";;
"$SSID_Site" ) LOCATION="$Location_Site";;
esac
REASON="SSID changed to $SSID"
# Location_Automatic
if [ -z "$LOCATION" ]; then
LOCATION="$Location_Automatic"
REASON="Automatic Fallback"
fi
# change network location
scselect "$LOCATION"
case $LOCATION in
"$Location_Automatic" )
osascript -e 'display notification "Network Location Changed to Automatic" with title "Network Location Changed"'
;;
"$Location_Office" )
osascript -e 'display notification "Network Location Changed to Office" with title "Network Location Changed"'
;;
"$Location_Site" )
osascript -e 'display notification "Network Location Changed to Site" with title "Network Location Changed"'
;;
esac
echo "--> Location Changer: $LOCATION - $REASON"
exit 0
This thread explains how to get the current network location.
I added the following code to get the current network location before making any changes:
CurrLoc=$(scselect | awk '{if ($1=="*") print $3}' | sed 's/[()]//g')
And then a simple if statement to exit the script early if the evaluated "new" network location matched the existing one:
if [ "$CurrLoc" = "$LOCATION" ]
then
exit 0
fi
# existing code to change network location and show notifications

ksh - exit script if last alphabet in variable is p

I'm writing a ksh script to refresh schema from prod to dev/test/qa environment. I would like to have disaster check in place, I'm asking user to input source and target database as well as schema names. When the user accidentally enter prod database as target database name I would like the script to exit. In our environment the production database name ends with p some times followed by 01, 02, 03 etc.
example names:
dbp
dbpp
dbpp01
dbpp02
cdp01
sedpbp
retpp01
PORP01
PORPP01
How can I check if the last alphabet not number of my variable string is p or P ?.
Try the following :
SCHEMA=dbp
case $SCHEMA in
*[pP] | *[pP]0[0-9] ) echo OK
;;
* ) echo Error
;;
esac
I have added another check which checks if the source and target database names are same as well.
case "$tarSID" in
*[pP] | *[pP]0[0-9] | "$tarSID"="SsrcSID")
echo "Warning: Target Database Cannot be Prod or same as Prod"
echo "Re-Enter Target Database Name
;;
* )
;;
Thanks again Alvin

Debugging with PhpStorm locally

Kind of a noob question. I'm uploading to a remote server. I've been advised to debug locally (versus remotely). How am I to pull up my files in a browser, then use the debugging tools in PhpStorm? As it stands, my remote host (in PhpStorm) is configured. I've done my own research but can't seem to find a clear answer. Thanks!
There is a "zero-configuration" debugging as described in docs. Also if in trouble try this xdebug settings:
; path to your php_xdebug extension file
; download from https://xdebug.org/wizard.php
zend_extension="c:\xampp-php7\php\ext\php_xdebug-2.4.0-7.0-vc14.dll"
; disables profiler globally
xdebug.profiler_enable = 0
; allows enabling it selectively with request parameter "XDEBUG_PROFILE"
xdebug.profiler_enable_trigger = 1
; directory to output profiler files to
xdebug.profiler_output_dir = "C:\xampp-php7\tmp"
; profiler file name (with request uri and timestamp)
xdebug.profiler_output_name = "%R-%t.cgout"
; enables debugger
xdebug.remote_enable = 1
; selects the dbgp protocol
xdebug.remote_handler = "dbgp"
; host where debug client is running
xdebug.remote_host = "localhost"
; debugger port
xdebug.remote_port = 9000
; disables xdebug traces in error messages - use https://tracy.nette.org/ instead
xdebug.default_enable = "Off"
; makes sure that the process does not freeze when there is no debug client
xdebug.remote_autostart = 0
I created a gist for easier sharing

Bash case not properly evaluating value

The Problem
I have a script that has a case statement which I'm expecting to execute based on the value of a variable. The case statement appears to either ignore the value or not properly evaluate it instead dropping to the default.
The Scenario
I pull a specific character out of our server hostnames which indicates where in our environment the server resides. We have six different locations:
Management(m): servers that are part of the infrastructure such as monitoring, email, ticketing, etc
Development(d): servers that are for developing code and application functionality
Test(t): servers that are used for initial testing of the code and application functionality
Implementation(i): servers that the code is pushed to for pre-production evaluation
Production(p): self-explanatory
Services(s): servers that the customer needs to integrate that provide functionality across their project. These are separate from the Management servers in that these are customer servers while Management servers are owned and operated by us.
After pulling the character from the hostname I pass it to a case block. I expect the case block to evaluate the character and add a couple lines of text to our rsyslog.conf file. What is happening instead is that the case block returns the default which does nothing but tell the person building the server to manually configure the entry due to an unrecognized character.
I've tested this manually against a server I recently built and verified that the character I am pulling from the hostname (an 's') is expected and accounted for in the case block.
The Code
# Determine which environment our server resides in
host=$(hostname -s)
env=${host:(-8):1}
OLDFILE=/etc/rsyslog.conf
NEWFILE=/etc/rsyslog.conf.new
# This is the configuration we need on every server regardless of environment
read -d '' common <<- EOF
...
TEXT WHICH IS ADDED TO ALL CONFIG FILES REGARDLESS OF FURTHER CODE EXECUTION
SNIPPED
....
EOF
# If a server is in the Management, Dev or Test environments send logs to lg01
read -d '' lg01conf <<- EOF
# Relay messages to lg01
*.notice ##xxx.xxx.xxx.100
#### END FORWARDING RULE ####
EOF
# If a server is in the Imp, Prod or is a non-affiliated Services zone server send logs to lg02
read -d '' lg02conf <<- EOF
# Relay messages to lg02
*.notice ##xxx.xxx.xxx.101
#### END FORWARDING RULE ####
EOF
# The general rsyslog configuration remains the same; pull it out and write it to a new file
head -n 63 $OLDFILE > $NEWFILE
# Add the common language to our config file
echo "$common" >> $NEWFILE
# Depending on which environment ($env) our server is in, add the appropriate
# remote log server to the configuration with the $common settings.
case $env in
m) echo "$lg01conf" >> $NEWFILE;;
d) echo "$lg01conf" >> $NEWFILE;;
t) echo "$lg01conf" >> $NEWFILE;;
i) echo "$lg02conf" >> $NEWFILE;;
p) echo "$lg02conf" >> $NEWFILE;;
s) echo "$lg02conf" >> $NEWFILE;;
*) echo "Unknown environment; Manually configure"
esac
# Keep a dated backup of the original rsyslog.conf file
cp $OLDFILE $OLDFILE.$(date +%Y%m%d)
# Replace the original rsyslog.conf file with the new version
mv $NEWFILE $OLDFILE
An Aside
I've already determined that I can combine the different groups of code from the case block onto single lines (a total of two) using the | operator. I've listed it in the manner above since this is how it is coded while I'm having issues with it.
I can't see what's wrong with your code. Maybe add another ;; to the default clause. To find the problem add a set -vx as a first line. Will show you lots of debug information.

Where is the Postgresql config file: 'postgresql.conf' on Windows?

I'm receiving this message but I can't find the postgresql.conf file:
OperationalError: could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "???" and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "???" and accepting
TCP/IP connections on port 5432?
On my machine:
C:\Program Files\PostgreSQL\8.4\data\postgresql.conf
postgresql.conf is located in PostgreSQL's data directory. The data directory is configured during the setup and the setting is saved as PGDATA entry in c:\Program Files\PostgreSQL\<version>\pg_env.bat, for example
#ECHO OFF
REM The script sets environment variables helpful for PostgreSQL
#SET PATH="C:\Program Files\PostgreSQL\<version>\bin";%PATH%
#SET PGDATA=D:\PostgreSQL\<version>\data
#SET PGDATABASE=postgres
#SET PGUSER=postgres
#SET PGPORT=5432
#SET PGLOCALEDIR=C:\Program Files\PostgreSQL\<version>\share\locale
Alternatively you can query your database with SHOW config_file; if you are a superuser.
You can find it by following this path
C:\Program Files\PostgreSQL\13\data
On my machine:
C:\Program Files (x86)\OpenERP 6.1-20121026-233219\PostgreSQL\data
you will get postgressql.conf file
C:/programfiles/postgressql/14/data
you will also get the pg_hba to check username password
PGDATA is assumed as ConfigDir under Postgresql, this works under docker and normal installation as well, this is default configuration until not changed explicitly.
on my docker PGDATA is configure as "/var/lib/postgresql/data" hence all configuration can be found under this directory.
#------------------------------------------------------------------------------
# FILE LOCATIONS
#------------------------------------------------------------------------------
# The default values of these variables are driven from the -D command-line
# option or PGDATA environment variable, represented here as ConfigDir.
#data_directory = 'ConfigDir' # use data in another directory
# (change requires restart)
#hba_file = 'ConfigDir/pg_hba.conf' # host-based authentication file
# (change requires restart)
#ident_file = 'ConfigDir/pg_ident.conf' # ident configuration file
# (change requires restart)
# If external_pid_file is not explicitly set, no extra PID file is written.
#external_pid_file = '' # write an extra PID file
# (change requires restart)

Resources