SQL Developer- Session startup script - oracle-sqldeveloper

I would like to have every session in my SQL Developer to be set to the GMT timezone. Is there a way to setup a session startup script in SQL Developer for this?

You can create a script file, e.g. C:\Temp\startup.sql, containing:
alter session set time_zone = 'GMT';
Then go to the Preferences, from the Tools menu, and go to the top-level Database item in the panel on the left, and put the path to your file in 'filename for connection startup script' text box:
You can change other settings in your script as well, if they can't be set in the Preferences->Database->NLS section.
The settings are only picked up when you open a new connection - they don't seem to be reapplied when you reconnect or when you open a new SQL Worksheet under an existing connection.
When you connect the 'script output' window will say:
session SET altered.
In 4.0.1 anyway, but apparently not in 4.0.2; and if you then do something like:
select current_timestamp from dual;
then you'll see the GMT time regardless of your PC's locale settings:
CURRENT_TIMESTAMP
-----------------------------------
06-MAY-14 11.23.42.593143000 GMT
with the script, versus in my case this without:
CURRENT_TIMESTAMP
-----------------------------------
06-MAY-14 12.25.09.925466000 EUROPE
/LONDON
This is tested in version 4.0.1.14 and 4.0.2.15; I think it's always been possible but I'm not able to check previous versions.

I ran into this as well and have an alternative solution. I noticed this section of the Preferences
"Database" -> "NLS"
This shows some date/time formats. In my case the "default" for "Date Format" was "DD-MON-YY". I updated it to something more accurate and it then displays dates as I specified.
It does not show any output during the connection process but DOES 'alter the session'.

Related

How to set timezone on postgresql jdbc connection created by flyway?

I have a postgresql database that I deploy scripts to using flyway. I use the maven flyway plugin to launch the database build against the target database. In that build I have scripts that do things like:
create table my_table(
my_date_time timestamp with time zone not null
);
insert into my_table(my_date_time)
select '2000-01-01';
The postgresql database timezone is set to UTC. My client machine (that runs the maven/flyway build) is running CEST (UTC+2:00).
When the scripts run, the database interprets the string literal above as '1999-12-31 22:00:00+00:00' and writes that to storage.
It seems that the jdbc client connection created by flyway is not setting its client timezone to UTC, but is taking the timstamp string and interpreting it as '2000-01-01 00:00:00+02:00'.
How can I set the client timezone on the jdbc connection created by flyway to UTC? Is there a setting that can be placed in my flyway.conf file?
If I change my local machine timezone to UTC the problem goes away, but I'd rather not do that on my development workstation.
A colleague suggested the following
mvn -Duser.timezone=UTC flyway:migrate
Instead of just giving it a date, which postgres has to interpret, it would be better to fully specify the timestamp:
insert into my_table(my_date_time)
select '2000-01-01T00:00:00+00';
If that is not possible, you could try running mvn with -Duser.timezone=UTC but fully specifying the timestamp is the better option as it leaves no room for misinterpretation or misconfiguration.
Another way is to set session timezone in migration script itself
SET timezone TO 'UTC';
i use flyway CLI in a script. so setting correct timezone to the corresponding environment variable before executing flyway command works for me:
export TZ=GMT

Can I set a default schema for a connection in Oracle sql developer 4?

Is there a way to set the default schema for a Database connection in Oracle SQL Developer version 4+? I see this link for previous versions:
http://www.javaforge.com/project/schemasel
...but I can't figure it out for Oracle SQL Developer version 4.
The way to do this at the tool level would be to run a session startup script.
Create a text file 'logon.sql' with the script "alter session set current_schema = yourschema;"
Save it anywhere - I recommend saving it somewhere in your database install location.
In SQL Developer go to Tools -> Preferences -> Database
Check the box for "Run connection startup script on each new database connection"
Browse and select the above file.
That should make you default to that schema every time you login.

How to change the timezone of Oracle SQL Developer / Oracle Data Modeler?

Each time I run Oracle SQL Developer or Oracle Data Modeler I receive this error message:
ora-01882 "timezone region not found"
Digging a this issue, I found that both Oracle SQL Developer and Oracle Data Modeler says that my timezone is Europe/Berlin, which is not listed into the Oracle's system view V$TIMEZONE_NAMES.
So, I need to change the timezone in Oracle SQL Developer (not the database) to match the most similar timezone found in V$TIMEZONE_NAMES.
If you need to change the time zone of Oracle SQL Developer (or Oracle Data Modeler), then this is how to do it:
Go to the installation directory of Oracle SQL Developer.
Open the file located at: sqldeveloper/bin/sqldeveloper.conf.
At the end of file, add the following line: AddVMOption -Duser.timezone=GMT-4.
You will need to change the value GMT-4 to one that match one of the timezones in V$TIMEZONE_NAMES.
And that’s it!
This worked for me
AddVMOption -Duser.timezone=GMT+5
Try:
Oracle Sql Developer 4.1.3
Open config file.
sqldeveloper/sqldeveloper/bin/sqldeveloper.conf
Add end of the file.
AddVMOption -Duser.timezone=GMT
Restart your Oracle Sql Developer.
For me this worked:
1)
When in Windows 8, make sure you have authorization/rights over the sqldeveloper folder
(for me this is C:\Program Files\sqldeveloper, do a right-mouse click here and choose "Properties..." and then "Security" tab and on that tab press the "Edit" button and give yourself all the rights. [I have to guess these names in English because my Windows is not English)]
2) then follow the steps from Rubens Mariuzzo above, except the last one
3) AddVMOption -Duser.timezone=GMT+1
SELECT * FROM v$timezone_names gave me both Europe/Amsterdam and Europe/Berlin as options (both are GMT+1 but my location is Europe/Amsterdam). However using either of these names stil gave the ora-01882 "timezone region not found", only after changing to "timezone=GMT+1" did the bug disappear
This worked for me
AddVMOption -Duser.timezone=GMT+7
Tq
Sri lanka
AddVMOption -Duser.timezone=GMT+5.30

Postgres turn on log_statement programmatically

I want to turn on logging of all SQL statements that modify the database. I could get that on my own machine by setting the log_statement flag in the configuration file, but it needs to be enabled on the user's machine. How do you enable it from program code? (I'm using Python with psycopg2 if it matters.)
Turning on logging of SQL statements that modify the database can be achieved by:
ALTER SYSTEM SET log_statement TO 'mod';
-- Make it effective by triggering configuration reload (no server restart required).
SELECT pg_reload_conf();
-- To make sure the modification is not limited to the current session scope
-- it is better to log out from postgresql and log back in.
-- Check value of log_statement configuration, expected: mod
SELECT * FROM pg_settings WHERE name = 'log_statement';
This requires superuser access rights.
Check hereafter links to documentation for more details:
ALTER SYSTEM
pg_reload_conf()
The "it needs to be enabled on the user's machine" phrase is confusing, indeed... I assume you mean "from the user (client) side".
In Postgresql some server run-time parameters can be changed from a connection, but only from a superuser - and only for those settings that do not require a server restart.
I'm not sure if that includes the many log options. You might try with something like:
SELECT set_config('log_XXX', 'off', false);
where log_XXX is to be replaced by the respective logging setting, and 'false' by the value you want to set.
If that does not work, I guess you are out of luck.

connection time zone issue with jOra eclipse plugin

I started using the jOra eclipse plugin. The plugin seems pretty robust and I'm hoping to stop using SQLDeveloper for 95% of my database needs.
Many of our tables have columns of type TIMESTAMP with LOCAL TIME ZONE. I can connect to the oracle DB using a jdbc string and the plugin seems to function very well. However, when I try to update one of these TIMESTAMP with LOCAL TIME ZONE values, I get a sql exception: java.sql.SQLException: connection session time zone was not set.
Does anyone know how I can set the time zone through the jdbc connection url? jOra doesn't seem to support adding custom connection properties, so the connection URL is really my only option.
Update: Running version 1.0.1, which I believe is the latest version.
Update2: Apparently I can perform an update statement in the sql worksheet just fine, just can't use their detail browser interface to update.
What version do you use? According to their release notes this issue was already fixed in 0.9.0. Consider upgrading. If still in vain, I'd report a bug over there, they seem to maintain it well enough.
After you connect to the DB, try running:
ALTER SESSION SET time_zone='+01:00';
Alternatively you could create a system trigger:
CREATE OR REPLACE TRIGGER setSessionTZ
AFTER LOGON ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'ALTER SESSION SET time_zone=''+01:00''';
END;