index returns relation "search_name_0" does not exist in "Starting rank 2" - indexing

I have generated nominatim database before and never faced such an issue.
Please tell me which "setup.php" command generates the "search_name_0" and such tables?
Full error output is:
-bash-4.2$ ./utils/setup.php --index --threads 8 --osm2pgsql-cache 24000
nominatim version 2.5.1
Starting indexing rank (0 to 4) using 8 threads
Starting rank 0
Done 0 in 0 # 0.000000 per second - FINISHED
Starting rank 1
Done 0 in 0 # 0.000000 per second - FINISHED
Starting rank 2
index_placex: UPDATE failed: ERROR: relation "search_name_0" does not exist
LINE 1: DELETE from search_name_0 WHERE place_id = in_place_id
^
QUERY: DELETE from search_name_0 WHERE place_id = in_place_id
CONTEXT: PL/pgSQL function deletesearchname(integer,bigint) line 1260 at SQL statement
PL/pgSQL function placex_update() line 75 at assignment
index_placex: UPDATE failed: ERROR: relation "search_name_0" does not exist
LINE 1: DELETE from search_name_0 WHERE place_id = in_place_id
^
QUERY: DELETE from search_name_0 WHERE place_id = in_place_id
CONTEXT: PL/pgSQL function deletesearchname(integer,bigint) line 1260 at SQL statement
PL/pgSQL function placex_update() line 75 at assignment
index_placex: UPDATE failed: ERROR: relation "search_name_0" does not exist
LINE 1: DELETE from search_name_0 WHERE place_id = in_place_id
^
QUERY: DELETE from search_name_0 WHERE place_id = in_place_id
CONTEXT: PL/pgSQL function deletesearchname(integer,bigint) line 1260 at SQL statement
PL/pgSQL function placex_update() line 75 at assignment
index_placex: UPDATE failed: ERROR: relation "search_name_0" does not exist
LINE 1: DELETE from search_name_0 WHERE place_id = in_place_id
^
QUERY: DELETE from search_name_0 WHERE place_id = in_place_id
CONTEXT: PL/pgSQL function deletesearchname(integer,bigint) line 1260 at SQL statement
PL/pgSQL function placex_update() line 75 at assignment
ERROR: Error executing external command: /srv/Nominatim-2.5.1/nominatim/nominatim -i -d nominatim -P 5432 -t 8 -R 4
Error executing external command: /srv/Nominatim-2.5.1/nominatim/nominatim -i -d nominatim -P 5432 -t 8 -R 4
-bash-4.2$

It took some time to figure out but it happens when your "create-partition-tables" part of setup fails.
Restarting it will fail to re-create the tables. I had to manually remove all partition tables and then restarted the setup with "create-partition-tables" key to solve this!

Related

hivevars not going through with beeline in emr

I am running a hive sql script in emr. I am calling the script from beeline (in a shell file) with some hivevars. But they are not going through to the script. Am I missing something obvious?
This is my shell script:
ST_DATE=$(TZ=America/Los_Angeles date +%Y-%m-%d -d "today");
beeline -u jdbc:hive2:// --hivevar ST_DATE="$ST_DATE" --hivevar lookback=45 -f ./ETL/predict_etl_hive.sql || exit 1
And this is how the hive sql file is
-- DEBUG display hivevars
select '${hivevar:lookback}';
select '${hivevar:ST_DATE}';
------------------- STEP 1: ----------------------------
DROP TABLE IF EXISTS string1.us_past_con_${hivevar:lookback}d;
CREATE TABLE IF NOT EXISTS string1.us_past_con_${hivevar:lookback}d
However it does not take the values. when using select to get the values it stays as the name:
0: jdbc:hive2://>
0: jdbc:hive2://> -- DEBUG display hivevars
0: jdbc:hive2://> select '${hivevar:lookback}';
+----------------------+
| _c0 |
+----------------------+
| ${hivevar:lookback} |
+----------------------+
0: jdbc:hive2://> select '${hivevar:ST_DATE}';
+---------------------+
| _c0 |
+---------------------+
| ${hivevar:ST_DATE} |
+---------------------+
And then it eventually fails at the DROP line:
FAILED: ParseException line 1:46 missing EOF at '$' near 'us_past_con_'
22/07/06 21:53:11 [ef15917c-31f8-48ae-8ca4-770871367e05 main]: ERROR ql.Driver: FAILED: ParseException line 1:46 missing EOF at '$' near 'us_past_con_'
org.apache.hadoop.hive.ql.parse.ParseException: line 1:46 missing EOF at '$' near 'us_past_con_'
The vars do go through if I use hive -f instead of beeline

integer expression expected shell scripting - BASH

I am trying to get the LAG between Primary & Standby database using the below shell script. The query works fine returning the values "DATABASE IS OUTOFSYNC" or "DATABASE IS INSYNC" for an instance that has 1 Node which returns a single value, but I get an error "[: 0 1: integer expression expected" for an instance that has two Nodes which returns two values for the LAG on the first Node and the Second Node.
So here is the code:
#!/bin/bash
get_status=$(sqlplus -s "/as sysdba" <<EOF
set pagesize 0 feedback off verify off heading off echo off;
SELECT prim.seq - tgt.seq seq_gap
FROM
(
SELECT thread#, MAX(sequence#) seq, MAX(completion_time) tm
FROM
v\$archived_log
GROUP BY
thread#
)
prim,
(
SELECT thread#, MAX(sequence#) seq, MAX(completion_time) tm
FROM
v\$archived_log
WHERE
dest_id IN
(
SELECT
dest_id
FROM
v\$archive_dest
WHERE
target = 'STANDBY'
)
AND
applied = 'YES'
GROUP BY
thread#
)
tgt
WHERE
prim.thread# = tgt.thread#;
exit;
EOF
)
if [ "$get_status" -ge 5 ]; then
echo "DATABASE IS OUTOFSYNC"
else
echo "DATABASE IS INSYNC"
fi
Is there a better way to write this script?
After adding typeset -p get_status after the query and before the if I get the below results:
declare -- get_status=" 1
0"
./dgtest2.sh: line 41: [: 1
0: integer expression expected
DATABASE IS INSYNC
The query is returning more than one value/string (for 2 nodes or threads) as shown in picture/screenshot and it seems like my script is only coded to address a single value/string generated by the query.
enter image description here
Is there away to modify the script to address multiple values/strings generated by the query
The logic should be if all values returned are -ge 5 it should report "DATABASE IS OUTOFSYNC" else "DATABASE IS INSYNC" for all values returned are -lt 5.
The logic for one value -lt 5 and one value -ge 5 would not suffice as the values constantly change on the database.
Any values from 0 - 4 that the database returns whether from both Nodes should report as "DATABASE IS INSYNC" and any value from 5 upwards that the database returns whether from both Nodes should report as "DATABASE IS OUTOFSYNC".
One idea would be to capture the status values (returned by the sqlplus script) into an array and then loop through the array testing said status values.
Instead of:
variable=$(sqlplus ...)
We want:
variable=( $(sqlplus ...) )
For OP's current scripting, with a name change for the variable, we will replace this:
get_status=$(sqlplus -s "/as sysdba" <<EOF
set pagesize 0 feedback off verify off heading off echo off;
SELECT prim.seq - tgt.seq seq_gap
...
exit;
EOF
)
With this:
status_array=( $(sqlplus -s "/as sysdba" <<EOF
set pagesize 0 feedback off verify off heading off echo off;
SELECT prim.seq - tgt.seq seq_gap
...
exit;
EOF
) )
One idea for the follow-on logic testing:
default database status is INSYNC
if any status values are -ge 5 then set database status to OUTOFSYNC
The code for this looks like:
db_status='INSYNC'
for status in "${status_array[#]}"
do
[[ "${status}" -ge 5 ]] && db_status='OUTOFSYNC' && break
done
echo "DATABASE IS ${db_status}"
I'm not setup to run the sqlplus script but I should be able to simulate the results with the following array assignments:
status_array=(1)
status_array=(7)
status_array=(0 1)
status_array=(5 7)
status_array=(5 3)
Running our code for each of these array assignments gives us:
##################### status_array=(1)
DATABASE is INSYNC
##################### status_array=(7)
DATABASE is OUTOFSYNC
##################### status_array=(0 1)
DATABASE is INSYNC
##################### status_array=(5 7)
DATABASE is OUTOFSYNC
##################### status_array=(5 3)
DATABASE is OUTOFSYNC

Don't understand where is syntax error ? PostgreSQL 11

PostgreSQL version : 11.1
Platform : OSX Mojave 10.14.1
That's my SQL code:
COPY (select nom,prenom,num_carte,pdv_carte,email,date_naissance from compte where num_carte != '' order by id_compte) TO :export_file WITH DELIMITER AS ';' CSV FORCE QUOTE * ENCODING 'UTF-8';
That line is in a .sql file called by shell script like this :
psql --dbname=test -U postgres --set adresses=$DATA_ADRESSE --set export_file="$EXPORT_FILE" --file=$ANO_SQL 1>>$ANO_LOG
With EXPORT_FILE variable declared like that :
export EXPORT_FILE=‎⁨"'export_for_fid.csv'"
Tried many solutions but none worked, always the same syntax error:
ERROR: syntax error at or near "‎⁨"
LINE 1: ...where num_carte != '' order by id_compte) TO ‎⁨'export_for_fid.csv' WITH D...
^
Instead of using --file and --set arguments, you could use a here-document in your shell script: (NOTE: I replaced the COPY by a \COPY )
#!/bin/sh
EXPORT_FILE="export_for_fid.csv"
DB_NAME="test"
psql --dbname=${DB_NAME} -U postgres <<OMG
\COPY (select nom,prenom,num_carte,pdv_carte,email,date_naissance from compte where num_carte <> '' order by id_compte) TO '${EXPORT_FILE}' WITH DELIMITER AS ';' CSV FORCE QUOTE * ENCODING 'UTF-8';
OMG
#eof

`FOR UPDATE` breaks batch execution in HANA

HANA 102.05 fails to execute the following code:
CREATE TABLE ATABLE( f INT );
CREATE PROCEDURE TestProc()
AS
BEGIN
SELECT f FROM ATABLE
FOR UPDATE; -- Without FOR UPDATE it works
END;
SELECT 'Hello' FROM DUMMY;
complaining that:
SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near "SELECT": line 8 col 2 (at pos 124)
which points outside the proceudure, at SELECT 'Hello'. The procedure itself compiles without error. The entire script completes successfully if I remove the FOR UPDATE directive. What is wrong with the original?
Update
When I execute the same query from hdbsql.exe I get:
0 rows affected (overall time 26,076 msec; server time 6518 usec)
* 257: sql syntax error: line 5 col 9 (at pos 71) SQLSTATE: HY000
* 257: sql syntax error: incorrect syntax near "END": line 2 col 1 (at pos 32) SQLSTATE: HY000
'Hello'
"Hello"
1 row selected (overall time 4644 usec; server time 143 usec)

Command line script to delete Oracle records based on a column value

I am completely new to scripting techniques.
My requirement is
To connect oracle through DOS script
Based on a column value need to delete the particular record
eg:
emp sal pt_dt
a 23 22-02-11
b 34 20-01-10
c 45 23-09-85
d 56 30-3-11
Based on the 30-3-11(pt_dt column), I need to delete the record d.
OS - Windows XP
DB - Oracle 10g
Simplest method is to first write your sql (e.g. deleterec.sql) script, then call it from a batch (e.g. deleterec.bat) script.
Example contents of deleterec.sql:
DELETE emp WHERE pt_dt = TO_DATE('30-03-2011','DD-MM-RRRR');
Example contents of deleterec.bat:
sqlplus.exe scott/tiger#orcl #deleterec.sql
(replace scott/tiger#orcl with your user name, password and database instance)
You can write a .bat like this:
#echo off
if %%1X==X goto noparam
echo DELETE FROM emp e WHERE e.emp = '%%1' > deleterec.sql
sqlplus.exe scott/tiger#orcl #deleterec.sql
delete deleterec.sql
goto end
:noparam
echo Usage: %%0 {employee id}
goto end
:end
echo Bye!
I admit I stole the sqlplus call from Jeffrey's answer. :-o