Postgres command line install from zip file fails to properly start the windows service after the database has been configured - postgresql

Below is the batch file I am kicking off at the end of an installer to properly configure my postgres database, however there comes an issue wherein the service is unable to be started.
This is what the service parameters look like:
C:\Program Files\pgsql\bin/pg_ctl.exe runservice -N "MyPostGres" -D "C:/Program Files/pgsql/PGDATA"
Batch file
#echo off
if "%1" == "" goto displayUsage
if "%2" == "" goto displayUsage
if "%3" == "" goto displayUsage
goto setup
:displayUsage
echo supply arguments: SUPER_USER_NAME SUPER_USER_PASSWORD USER_PASSWORD \ >> C:\myLog.log
goto end
:setup
echo %~1 >> C:\myLog.log
echo %~2 >> C:\myLog.log
echo %~3 >> C:\myLog.log
echo calling initdb! >> C:\myLog.log
initdb -U MY_PG ../PGDATA
echo calling pg_ctl register! >> C:\myLog.log
rem provide a variable for PGDATA
pg_ctl register -N TravisPostGres -U MY_PG -P wooo! -D "C:\Program Files\pgsql\PGDATA"
echo calling pg_ctl start! >> C:\myLog.log
pg_ctl start -D ../PGDATA -w
echo calling createuser! %~1 >> C:\myLog.log
createuser -s -UMY_PG %~1
:end
echo the end! >> C:\myLog.log
exit /B 0

I discovered that the issue was the existence of the following file
C:\Program
This file is invisible via explorer view but when executing dir from the c directory it was shown as a 0k file. Deleting this file proved to be the fix.

Related

can't connect remote server db2 command line

i am try to connect another server using db2 command CONNECT TO 192.168.131.16db2admin:25000/SAMPLE USER db2admin USING Password#123 but remote server not connect Error Display on SQL0104N An unexpected token "192.168.131.16db2admin:25000/SAMPLE" was found
following "TO". Expected tokens may include: "".
SQLSTATE=42601..please give any solution
If you don't want to catalog the remote database, you may construct the configuration file on the fly to make it work with the Db2 command line processor.
The script constructs temporary configuration file and uses the corresponding environment variable with this file name saving its previous value and reverting it back after the db2 connect command.
Linux & Unix example
#!/bin/sh
if [ $# -eq 0 ]; then
echo "Usage: . ./db2connect host:port/dbname USER username [USING password]" >&2
exit 1
fi
DSN=${1}
CFGFILE=./db2dsdriver.cfg.$$
dbname=${DSN#*/}
hp=${DSN%/*}
host=${hp%:*}
port=${hp#*:}
cat > ${CFGFILE} <<EOF
<configuration>
<dsncollection>
<dsn alias="${dbname}" name="${dbname}" host="${host}" port="${port}"/>
</dsncollection>
<databases>
<database name="${dbname}" host="${host}" port="${port}"/>
</databases>
</configuration>
EOF
cfg_bkp=${DB2DSDRIVER_CFG_PATH}
export DB2DSDRIVER_CFG_PATH=${CFGFILE}
shift
db2 connect to ${dbname} "$#"
export DB2DSDRIVER_CFG_PATH=${cfg_bkp}
rm -f ${CFGFILE}
Usage:
. ./db2connect 192.168.131.16:25000/SAMPLE USER db2admin USING Password#123
Don't remove space between the 1-st dot and the path to this executable file.
Windows example:
#echo off
if [%1] == [] (
echo Usage: %~nx0 host:port/dbname USER username [USING password]
goto :eof
)
set cfg_bkp=%DB2DSDRIVER_CFG_PATH%
set CFGFILE=.\db2dsdriver.cfg.tmp
set DB2DSDRIVER_CFG_PATH=%CFGFILE%
for /F "tokens=1-3 delims=:/" %%i in ('echo %1') do (
set host=%%i
set port=%%j
set dbname=%%k
)
if exist %CFGFILE% del %CFGFILE%
db2cli writecfg add -database %dbname% -host %host% -port %port% > nul
db2cli writecfg add -dsn %dbname% -database %dbname% -host %host% -port %port% > nul
db2 terminate
db2 connect to %dbname% %2 %3 %4 %5
set DB2DSDRIVER_CFG_PATH=%cfg_bkp%
del %CFGFILE%
Usage:
db2connect.bat 192.168.131.16:25000/SAMPLE USER db2admin USING 'Password#123'

Error when try to send email with sendEmail

I want to use sendEmail to send automated emails.
If i run the following line separately it works:
sendemail.exe -f "payslip#dgroup.com" -t "dn.john#dgroup.com" -u "Payslip: DN JOHN, marca 1567, may 2021" -o message-file=mail_body_payslip.txt -o tls=no -o username="payslip#dgroup.com" -o password="hfsjfb&^%" -s webmail.dgroup.com:26 -o timeout=5 -xu payslip#dgroup.com -xp hfsjfb&^% -a "C:\Payslips\encrypted\2021_05_1702_DN_JOHN.pdf" -l email_log.txt
However if i try to run it from a bat file it doesn't work.
Here is the bat file:
#echo.
#echo.
echo Starting email session... >> email_log.txt
date /t >> email_log.txt
time /t >> email_log.txt
#echo.
#echo Verifying files...
#echo.
#echo Sending mails...
sendemail.exe -f "payslip#dgroup.com" -t "dn.john#dgroup.com" -u "Payslip: DN JOHN, marca 1567, may 2021" -o message-file=mail_body_payslip.txt -o tls=no -o username="payslip#dgroup.com" -o password="hfsjfb&^%" -s webmail.dgroup.com:26 -o timeout=5 -xu payslip#dgroup.com -xp hfsjfb&^% -a "C:\Payslips\encrypted\2021_05_1702_DN_JOHN.pdf" -l email_log.txt
#echo.
#echo.
#echo Payslip was sent. Verify email_log.txt
#echo.
#pause
When i run the bat file I get the following error:
Jun 16 14:01:55 srv3 sendemail.exe[2532]: ERROR => Connection attempt to localhost:25 failed: IO::Socket::INET: connect: Unknown error
If I run telnet localhost:25 I get this:
Could not open connection to the host, on port 23: Connect failed
What could be the problem? Why is running fine separately but executed from bat file I get error?
I've found the problem.
When you run the bat file the "%" character found in the password was replaced with "26" therefore the password was incorrect.
The solution is to use %% instead of %.
Two %% equals to one %.

PostgreSQL: Automated Backup in Windows

I'm trying to create an automated backup in Postgresql using below link, but I don't know where to find the needed dll, I'm stuck here. Can't proceed to next instruction because of this. Can anyone knows how to do it? Need help please.
https://wiki.postgresql.org/wiki/Automated_Backup_on_Windows
comerr32.dll
gssapi32.dll
k5sprt32.dll
krb_32.dll
libeay32.dll
libiconv2.dll
libpq.dll
Microsoft.VC80.CRT.manifest
msvcm80.dll
msvcp80.dll
msvcr80.dll
pg_dump.dll
ssleay32.dll
zlib1.dll
Here's batch file script:
#echo off
for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
set dow=%%i
set month=%%j
set day=%%k
set year=%%l
)
set datestr=%month%_%day%_%year%
echo datestr is %datestr%
set BACKUP_FILE=<backup_name_>_%datestr%.backup
echo backup file name is %BACKUP_FILE%
SET PGPASSWORD=<password>
echo on
bin\pg_dump -i -h <localhost> -p 5432 -U <postgres> -F c -b -v -f %BACKUP_FILE% <db_name>
Is there missing syntax?
When manually executed error shows:
bin\pg_dump: illegal option -- i
I execute something like this
pg_dump.exe -h %SERVER% -p 5432 -U postgres -Fc -d %basedatos% -v -f %filebackup%
This variables replace value respective.

VBS opens a CMD but can't read next commands to go on other directory

I am trying to create vbs file so that it will be executed by the MS Scheduler in order to backup my Postgresql database because i can't seem to find a way in using agent since i installed it but it is not appearing in the UI of PGAdmin III that was installed when i used Odoo. I am using windows 10.
Here is my .vbs file
Set ShellCmd = WScript.CreateObject("WScript.Shell")
ShellCmd.run "cmd cd\ cd 'Program Files' cd Odoo 9.0-20161004 cd PostgreSQL cd bin pg_dump -h localhost -p 5432 -U openpg -f 'C:/BackupFiles/Sample.backup' -d 120120161800"
WScript.Echo "Success!"
When i run this, the command line isn't going anywhere. Even just "cmd cd\" the cmd does nothing. I'ts a quite simple problem but i can't get my automated backup working if i can't run a simple vbs command
Instead of using a vbs script, you should just use a .bat or .cmd batch file:
c:
cd "\Program Files\Odoo 9.0-20161004\PostgreSQL\bin"
pg_dump -h localhost -p 5432 -U openpg -f 'C:/BackupFiles/Sample.backup' -d 120120161800"
Generally, we do not use ShellCmd.run "cmd ...." in vbs to execute multiple commands in one statement.
Your ShellCmd is heavily broken. I suggest instead of using .Run take the .Exec method to catch the output - at least until problems are solved. I don't know if your pg_dump requires to be run inside that same folder, if not this might work:
Dim WshShell, oExec, s
Set WshShell = CreateObject("WScript.Shell")
Program = """C:\Program Files\Odoo 9.0-20161004\PostgreSQL\bin\pg_dump"""
Options = " -h localhost -p 5432 -U openpg -f 'C:/BackupFiles/Sample.backup' -d 120120161800"
Set oExec = WshShell.Exec(Program & Options)
Do While Not oExec.StdOut.AtEndOfStream
s = s & oExec.StdOut.ReadLine() & vbCrLf
Loop
WScript.Echo "oExec.Status=" & oExec.Status
Wscript.Echo s

How can I create and drop a postgres database using Liquibase?

How can I create a postgres database using Liquibase?
I want to execute the following command by Liquibase:
create database db_name owner user_name;
How can I create and drop a postgres database using Liquibase?
I want to execute the following command by Liquibase:
drop database db_name;
I can create this using
create own bat file
read liquibase.property file from it
create Db
run liquibase.jar update
echo off
FOR /F "eol=; tokens=2,2 delims==" %%i IN ('findstr "url" liquibase.properties') DO set url=%%i
echo %url%
FOR /f " tokens=3,3 delims=/" %%i IN ("%url%") DO set url2=%%i
echo %url2%
Echo "Starting Deployment" >> Deploy.log
Echo "Create Database"
psql.exe -h %1 -p %2 -U %3 -c "create database %url2%" >> Deploy.log
Echo "Call liquibase script"
start liquibase.jar update>> Deploy.log
Echo "Liquibase Script End"