Oracle table entries lost. - sql

Yesterday I installed Oracle 11g & Oracle Data Access. With the installed sql*plus console I used /nolog and the connect / as SYSDBA, then I created a few users and grand them privilegs.
I created a table and insert some values. After closing and reopening the console, the table exists but the entries are lost.
I also tried to login in as an user and created a table... but after restart the entries are lost again.
Could it be that the enviroment variable is wrong?

Like John said, use the commit; statement to make your changes permanent.

Related

How can I know what changed in a SQL database for a certain time?

I have a system to manage printers of a company and I need to understand how the workflow between the Website and database works by knowing what is added/changed in the database with each interaction of the user. Is there a way to find or create some kind of log for a database or even the entire SQL Server that can show me what I need?
you can use extended events feature in some case :
https://learn.microsoft.com/en-us/sql/relational-databases/extended-events/quick-start-extended-events-in-sql-server?view=sql-server-2017
I think what you're looking for are triggers.
You can make tables to log the currently updated or changed data and use triggers to automatically feed data in the log table on any change
CREATE OR REPLACE TRIGGER [trigger_name]
BEFORE DELETE OR INSERT OR UPDATE ON [table_name]
FOR EACH ROW
WHEN [some condition]
DECLARE
[variable declaration]
BEGIN
[create an entry in the log table here]
END;
You can use NEW and OLD keywords to refer to the data (new referring to the most recent update of data)
Just for the record, a tool for that exactly purpose exists and is installed together with SQL Server, it is called SQL Server Profiler.

Oracle error ORA-00942, rails 3 environment

Hoping someone will have some insight into this issue. There are a lot of posts regarding this error, and I have read all of them.
Running a Rails 3 app on an Oracle 11 db. Rails attempts to create a new object, and it blows up (500) and I get back ORA 00942, table or view does not exist. Table does exist. Sequence exists and I can both write to the table and pull sequence numbers using SQL Developer and the same credentials that are used to run the rails app. Permissions look fine. I have looked at the rails model associations, and tracked down all of the tables and sequences of those objects as well.
One of the columns in the table is a CLOB column, and it seems like there can be issues with that datatype. But those seem to come from Java environments.
I have schema owner credentials, is there a log I could check to see the exact sql statement that is causing the error? Any sort of lower level logging I could turn on to get more insight into what is going on?
This ended up being a missing grant on a sequence. Very frustrating that Oracle reports this as 00942.
If you get this problem, and the table is present, look carefully at the grants that have been made to both the table and the sequence. You can do this with the following syntax in SQL Developer:
select * from DBA_TAB_PRIVS where table_name = name_of_thing_you_want
Yes, sequences also fall under the table_name heading.
To create a grant:
grant select ON the_name_of_the_object TO name_of_the_user
I hope this helps someone.

Auditing logged in user with delete trigger

We have an audit option in our application, where we are auditing the deleted records from a table using AFTER DELETE ON trigger.
Problem description :
The problem that we face here is, we need to log the person who has deleted the record. We could not get id of the person deleted the record anywhere from the database as its not present. Its coming from the web application. My question is there anyway to get the name or id of the person who has logged into the web application in the database side.
We are using oracle 11g.
You should be able to do this using dbms_session package.Using the package you can set and get values.Hence , during the login to your application , you can set the value and finally while on delete trigger execution , get this and insert into the audit table.
This might come handy - http://www.dba-oracle.com/t_dbms_session.htm
Hope that helps !

Why does this query throw ORA-00942 on 10g while it works on 11g?

I execute this query without problem on my 11g installation :
SELECT
PRODUCT_INFOS_idm.FIELD_VALUE "mother_id",
PRODUCT_INFOS_ep.FIELD_VALUE "product_thickness",
COIL_INFOS.TIME_STAMP,
COIL_INFOS.IN_THICKNESS,
COIL_INFOS.MEASURED_LENGTH,
COIL_INFOS.MEASURED_WIDTH,
COIL_INFOS.PARAM_SET_TOP_SIDE,
COIL_INFOS.PARAM_SET_BOTTOM_SIDE
FROM
COIL_INFOS
INNER JOIN
PRODUCT_INFOS PRODUCT_INFOS_idm
on PRODUCT_INFOS_idm.COIL_ID_SYSTEM=COIL_INFOS.COIL_ID_SYSTEM
and PRODUCT_INFOS_idm.TIME_STAMP=COIL_INFOS.TIME_STAMP
and PRODUCT_INFOS_idm.FIELD_NAME='ID bobina'
INNER JOIN
PRODUCT_INFOS PRODUCT_INFOS_ep
on PRODUCT_INFOS_ep.COIL_ID_SYSTEM=COIL_INFOS.COIL_ID_SYSTEM
and PRODUCT_INFOS_ep.TIME_STAMP=COIL_INFOS.TIME_STAMP
and PRODUCT_INFOS_ep.FIELD_NAME='Anchura'
WHERE
(COIL_INFOS.COIL_ID_SYSTEM LIKE '14051800' OR COIL_INFOS.COIL_ID LIKE '14051800')
But when my customer (who may have a 10g installation) executes it, he gets
ORA-00942: table or view does not exist
Other queries show that he has the same tables and columns. The following queries executes without problem :
select count(*) from COIL_INFOS
select count(*) from PRODUCT_INFOS
What can be the problem ? Is there a syntax error somewhere ? I suspect there is a problem with the Oracle version (I already had to remove the "as" I usually use for column aliasing). Does Oracle 10g support table aliasing ?
There are several reasons why we might get ORA-00942.
The most obvious one is, the table does not exist in the database. That's easy enough to check in the data dictionary views, such as DBA_TABLES.
The table exists but we are referencing it wrongly. The common scenario is when the table was created with a mixed-case name in double quotes; when this happens we always have to refer to the table name with a mixed-case name in double quotes, because EMPLOYEES != "Employees".
The table is owned by a different user and our code doesn't include the schema name when we call it (and we don't have a synonym either).
The table is owned by a different user and that user hasn't granted us privileges on it.
The table is owned by a different user and that user has granted us privileges on it through a role but we want to reference it in a stored procedure or a view. In this situation we must have the privileges granted to our user directly, because the Oracle Security model works that way.
Given that you say "Other queries show that he has the same tables and columns" we can rule out the first option, and probably the second one. So it's most likely a problem with a missing synonym or missing permissions.
As was hinted by Bob in comments, the problem was due to a bad version of Oracle 10g.
There are a few servers on which the same schema and the same query are used, only the one with version 10.2.0.1.0 had the problem. Oracle experts think the bug doesn't exist on 10.2.0.4 but I have no access to Oracle bug database.
As patching the server was out of question for our customer, we finally got around the bug by creating a view for this query.
TLDR : when Oracle says a version is buggy and should not be used, it should not be used.
There's no problem with Oracle version. You are using standard queries that will work in even older version of Oracle than 10.
I suspect one or more of the following will be true:
you may have synonyms in your 11g database but not in 10g at the client.
The client is using different credentials to test select count(*) from table than that used to run the query.

PostgreSQL - Rename database

I need to rename the database but when I do in
PGAdmin : ALTER DATABASE "databaseName" RENAME TO "databaseNameOld" it told me that it cannot.
How can I do it?
(Version 8.3 on WindowsXP)
Update
The first error message : Cannot because I was connect to it. So I selected an other database and did the queries.
I get a second error message telling me that it has come user connect. I see in the PGAdmin screen that it has many PID but they are inactive... I do not see how to kill them.
Try not quoting the database name:
ALTER DATABASE people RENAME TO customers;
Also ensure that there are no other clients connected to the database at the time. Lastly, try posting the error message it returns so we can get a bit more information.
For future reference, you should be able to:
-- disconnect from the database to be renamed
\c postgres
-- force disconnect all other clients from the database to be renamed
SELECT pg_terminate_backend( pid )
FROM pg_stat_activity
WHERE pid <> pg_backend_pid( )
AND datname = 'name of database';
-- rename the database (it should now have zero clients)
ALTER DATABASE "name of database" RENAME TO "new name of database";
Note that table pg_stat_activity column pid was named as procpid in versions prior to 9.2. So if your PostgreSQL version is lower than 9.2, use procpid instead of pid.
I just ran into this and below is what worked:
1) pgAdmin is one of the sessions. Use psql instead.
2) Stop the pgBouncer and/or scheduler services on Windows as these also create sessions
Unexist told me in comment to restart the database and it works! Restarting the database kill all existing connection and then I connect to an other database and was able to rename it with my initial query.
Thx all.
Instead of deploying a nuke (restarting the server) you should try to close those connections that bother you either by finding where are they from and shutting down the client processes or by using the pg_cancel_backend() function.
When connected via pgadmin, the default database will be postgres.
ALTER DATABASE postgres RENAME TO pgnew;
This will not work.
You need to right click on server in pgadmin and set Maintenance DB to some other DB and save. Then retry and it should work if no other connections exists.
For anyone running into this issue using DBeaver and getting an error message like this:
ERROR: database "my_stubborn_db" is being accessed by other users
Detail: There is 1 other session using the database.
Disconnect your current connection, and reconnect to the same server with a connection that doesn't target the database you are renaming.
Changing the active database is not enough.
ALTER DATABASE old_database RENAME TO new_database;
old_database means already existing database.
new_database means need to modify this name.
Example: ALTER DATABASE profile RENAME TO address;