Log postgres query messages - windows

How can I write the query result messages, which inform the user that the query was successful or not and the number of affected records, to log file in PostgreSQL.
I have tried to change log_statement to 'all' and log_min_duration_statement to 0 but all I get is the query text.
Is it possible to redirect those messages to log file in a Windows OS?

you can use GET DIAGNOSTICS for that.. And if you are a superuser, you can save result to a file...
create table tablename(version int);
insert into tablename select 9;
do
$$
declare
rc text;
begin
update tablename set version=version where false;
GET DIAGNOSTICS rc = ROW_COUNT;
raise info '%',' changed: '||rc;
update tablename set version=version where true;
GET DIAGNOSTICS rc = ROW_COUNT;
raise info '%',' changed: '||rc;
raise info '%','If you are superuser you can save result to a file...';
execute $e$copy(select '$e$||rc||$e$') to '/tmp/roes.log'$e$;
raise exception '%','raiseing error to rollback changes';
end;
$$
;
and the result looks:
INFO: changed: 0
INFO: changed: 1
INFO: If you are superuser you can save result to a file...
ERROR: raiseing error to rollback changes
********** Error **********
ERROR: raiseing error to rollback changes
SQL state: P0001

Related

"Commands out of sync" error when trying to execute a procedure in MySQL 8

When executing below code in phpMyAdmin:
use db;
DELIMITER $$
DROP PROCEDURE IF EXISTS McaTest3$$
CREATE PROCEDURE McaTest3()
BEGIN
SELECT
cl.*
FROM `condition_library` cl
LEFT JOIN condition_custom cc on cl.condition_library_id = cc.condition_library_id
and cc.active = 1
AND (cc.permit_application_id = 20231 OR cc.permit_id = NULL)
WHERE FIND_IN_SET(cl.`condition_library_id`, '13070')
AND cl.active = 1
and cc.condition_library_id IS NULL;
END$$
DELIMITER ;
call McaTest3();
Getting error:
Error
Static analysis:
1 errors were found during analysis.
Missing expression. (near "ON" at position 25)
SQL query: Edit Edit
SET FOREIGN_KEY_CHECKS = ON;
MySQL said: Documentation
#2014 - Commands out of sync; you can't run this command now
This happens when there is no record found in the table which is at LEFT JOIN.
When the same is ran in MySQL Workbench: NO ERROR and return empty dataset.
Same procedure when executed from Application (Appian) is failing as well… Any clues?
Another question on Stackoverflow answered my issue:
link: MySQL error #2014 - Commands out of sync; you can't run this command now

pin_rel issue while loading rated events (Error: Update Stored Procedure: 8003)

I'm getting the following error while loading the .out file using pin_rel
Error 02/28/16 10:46:56:0552 PM ( 1456728416552 ) T:Update SP Thread 1 REL RELUpdaterThread 1:ece:UnknownProgramName:0:Update SP Thread 1:0:1456728416:0
RA-20003: Error -20015error while processing data from event_essentials occurred in the update procedure start_obj_id0 = 1449525761317588038 end_obj_id0 = 1449525761317588038 sqlcode = -20015 sqlerrm = ORA-20015: precommit failed (with exception): 18838741
ORA-06512: at "PIN10.PIN_REL", line 4260
ORA-29532: Java call terminated by uncaught Java exception: DeterminateError - ERR_BAD_OPCODE
FList.java:0: ErrBuf Fields:
Error=ERR_BAD_OPCODE Loc=DM
Field=PIN_FLD_OP_SQL_TRACE Rec=0 reserved=35
Facility=0 MessageID=0 Time=4:00 PM Version=0 Reserved2=0
Args=<none>
Nested Error:
<none>
ORA-06512: at "PIN10.PIN_REL", line 4898
ORA-20015: precommit failed (with exception): 18838741
ORA-06512: at "PIN10.PIN_REL", line 4260
ORA-29532: Java call terminated by uncaught Java exception: DeterminateError - ERR_BAD_OPCODE
FList.java:0: ErrBuf Fields:
Error=ERR_BAD_OPCODE Loc=DM
Field=PIN_FLD_OP_SQL_TRACE Rec=0 reserved=35
Facility=0 MessageID=0 Time=4:00 PM Version=0 Reserved2=0
Error 02/28/16 10:46:56:0571 PM ( 1456728416575 ) T:main REL IREL 1:ece:UnknownProgramName:0:main:1:1456728415:0
Error encountered in the Update Stored Procedure: 8003
The update stored procedure encountered an error on an update statement.
Error 02/28/16 10:46:56:0575 PM ( 1456728416575 ) T:main REL IREL 1:ece:UnknownProgramName:0:main:1:1456728415:0
Exiting with return code: 8
One of the suggestion was to execute below listed .plb files present in pin_rel directory
pin_rel_tt_pre_updater_sp.plb*
pin_rel_updater_sp_oracle.plb*
suspense_updater_sp_oracle.plb*
pin_rel_tt_updater_sp.plb*
But this solution didn't work. Only event related tables are loaded, Item tables aren't populated.
set the ObjectCacheTypeOutputSplit to FALSE in pipeline registery. If this field is set to TRUE it will result in 2 identical output files from a single input EDR and write them to separate output streams.

Flyway callbacks with Oracle compile

I try to add before migration and after migration scripts as callbacks to flyway for compiling my views, procedures, functions etc.
Is there a possibility to stop it before a migration process or have a rollback when before or after scripts fail (or rather return a warning)?
Cause the only thing I see right now is I receive warnings like this
[WARNING] DB: Warning: execution completed with warning (SQL State: 99999 - Error Code: 17110)
and it goes on, without stopping.
I thought about FlywayCallback interface and it's implementation but I'm not entirely sure how it should be done with compiling.
I'm using Spring Boot 1.2.5 with the newest Flyway.
I have also same error. SQL State: 99999 - Error Code: 17110. i found this solution.
check which version under this warning and that version under sql script check have Trigger or any procedure which not closed properly.
close trigger or any procedure if oracle DB / end of trigger.
ex:
CREATE OR REPLACE TRIGGER Print_salary_changes
BEFORE DELETE OR INSERT OR UPDATE ON Emp_tab
FOR EACH ROW
WHEN (new.Empno > 0)
DECLARE
sal_diff number;
BEGIN
sal_diff := :new.sal - :old.sal;
dbms_output.put('Old salary: ' || :old.sal);
dbms_output.put(' New salary: ' || :new.sal);
dbms_output.put_line(' Difference ' || sal_diff);
END;
/
Flyway 5.0 now comes with a feature called Error Handlers that lets you do exactly this. You can now create an error handler that turns that warning into an error as simply as
import org.flywaydb.core.api.FlywayException;
import org.flywaydb.core.api.errorhandler.Context;
import org.flywaydb.core.api.errorhandler.ErrorHandler;
import org.flywaydb.core.api.errorhandler.Warning;
public class OracleProcedureFailFastErrorHandler implements ErrorHandler {
#Override
public boolean handle(Context context) {
for (Warning warning : context.getWarnings()) {
if ("99999".equals(warning.getState()) && warning.getCode() == 17110) {
throw new FlywayException("Compilation failed");
}
}
return false;
}
}
More info in the docs: https://flywaydb.org/documentation/errorhandlers
I had the same error when my scripts had a "CREATE TABLE XXX AS SELECT..." statement.
I fixed it by splitting it into two separate statements:
CREATE TABLE XXX (columns def...);
INSERT INTO TABLE XXX (columns...)
SELECT...;

DBD::Oracle::st execute failed: system generated message

For oracle system generated Software Error messages during prepare/execute query invalid. displays complete query to user on a webpage. want to replace system generated message with user common message.
example:
Software error:
DBD::Oracle::st execute failed: ORA-01722: invalid number (DBD ERROR: error possibly near <> indicator at char 136 in 'SELECT EQUIPID, EQUIPSHORTNAME, MAXLIMITEDDAYS, STATUS, EQUIPNAME FROM LAB_EQUIPMENT_DETAILS WHERE CATEGORYID = '3' AND SUBCATEGORYID = <>' ' AND STATUS != 'DELETE'') [for Statement "SELECT EQUIPID, EQUIPSHORTNAME, MAXLIMITEDDAYS, STATUS, EQUIPNAME FROM LAB_EQUIPMENT_DETAILS WHERE CATEGORYID = '3' AND SUBCATEGORYID = '****' AND STATUS != 'DELETE'"] at /proj/aa/bb/Source/Global_Routines_general_apps.pm line 126.
For help, please send mail to the webmaster ([...]), giving this error message and the time and date of the error.
Can anyone please help me in doing this.
Thanks in advance.
Simply wrap your execute statement in an eval block and catch the error.
eval {
$sth->execute();
...
};
if ( $# ) {
# log the full error message
write_log( $sth->errstr );
# and re-throw the common message
die 'HEY!!!! Something is messed up here!';
}

Test the existence of a Teradata table and create the table if non-existent

Our Continuous Inegration server (Hudosn) is having a strange issue when attempting to run a simple create table statement in Teradata.
This statement tests the existence of the max_call table:
unless $teradata_connection.table_exists? :arm_custom_db__max_call_attempt_parameters
$teradata_connection.run('CREATE TABLE all_wkscratchpad_db.max_call_attempt_parameters AS (SELECT * FROM arm_custom_db.max_call_attempt_parameters ) WITH NO DATA')
end
The table_exists? method does the following:
def table_exists?(name)
v ||= false # only retry once
sch, table_name = schema_and_table(name)
name = SQL::QualifiedIdentifier.new(sch, table_name) if sch
from(name).first
true
rescue DatabaseError => e
if e.to_s =~ /Operation not allowed for reason code "7" on table/ && v == false
# table probably needs reorg
reorg(name)
v = true
retry
end
false
end
So as per the from(name).first line, the test which this method is performing is just a simple select statement, which, in SQL, looks like: SELECT TOP 1 MAX(CAST(MAX_CALL_ATTEMPT_CNT AS BIGINT)) FROM ALL_WKSCRATCHPAD_DB.MAX_CALL_ATTEMPT_PARAMETERS
The above SQL statement executes perfectly fine within Teradata SQL Assistant, so it's not a SQL syntax issue. The generic ID which our testing suite (Rubymine) uses is also not the issue; that ID has select access to the arm_custom_db.
The exeption which I can see is being thrown (within the builds console output on Hudson) is
Sequel::DatabaseError: Java::ComTeradataJdbcJdbc_4Util::JDBCException. Since this execption is a subclass of DatabaseError, the exception shouldn't be the problem either.
Also: We use unless statements like this every day for hundreds of different tables, and all except this one work correctly. This statement just seems to be a problem.
The complete error message which appears in the builds console output of Hudson is as follows:
[2015-01-07T13:56:37.947000 #16702] ERROR -- : Java::ComTeradataJdbcJdbc_4Util::JDBCException: [Teradata Database] [TeraJDBC 13.10.00.17] [Error 3807] [SQLState 42S02] Object 'ALL_WKSCRATCHPAD_DB.MAX_CALL_ATTEMPT_PARAMETERS' does not exist.: SELECT TOP 1 MAX(CAST(MAX_CALL_ATTEMPT_CNT AS BIGINT)) FROM ALL_WKSCRATCHPAD_DB.MAX_CALL_ATTEMPT_PARAMETERS
Sequel::DatabaseError: Java::ComTeradataJdbcJdbc_4Util::JDBCException: [Teradata Database] [TeraJDBC 13.10.00.17] [Error 3807] [SQLState 42S02] Object 'ALL_WKSCRATCHPAD_DB.MAX_CALL_ATTEMPT_PARAMETERS' does not exist.
I don't understand why this specific bit of code is giving me issues...there does not appear to be anything special about this table or database, and all SQL code executes perfectly fine in Teradata when I am signed in with the same exact user ID that is being used to execute the code from Hudson.

Resources