I've used mysql shell for creating database (create database testdb), why can't i make a database in sql*plus command line. I also want to see the lists of database but i can't find queries anywhere. Please guide
SQL> create database testdb;
create database testdb
*
ERROR at line 1:
ORA-01501: CREATE DATABASE failed
ORA-01100: database already mounted
SQL>
I am running a test.sql file from command prompt by connecting to the database named DB. The test.sql file contains DDL, DML statments in it.
The Schemas named A and B are used in the test.sql file.
First connection to the schema connect&&schema A was made. The DDL, DML statements for schema A got executed.
Next connect&&schema B was made in that same test.sql file. So the script at run time asks for the value of schema name B. After the connection to schema B then the DDL, DML statements for schema B will be executed.
Please suggest if I can connect automatically to schema B without entering the value of schema B name at run time when running the test.sql file.
I am trying to import a db into my local xe instance. I have a problem in that it is greater than 11GB and things fall over. My db has audit tables (courtesy of envers). I do not need this data.
Two questions here:
can I expdp table structures and not data for the aud_ tables that are my audit tables
can I expdp on a different SID. My SID is not orcl but orcllo (for historical reason)
For the second question I have done the following but
sqlplus / as sysdba#orcllo
alter user MY_DB identified by MY_PASS ACCOUNT UNLOCK;
CREATE OR REPLACE DIRECTORY db_dumps AS '/tmp/db_dumps';
GRANT READ, WRITE ON DIRECTORY db_dumps TO MY_DB;
but when I run expdp I get an error about db_dumps not being found.
Thanks
Q.1:
You can use 'EXCLUDE' or 'INCLUDE' switch during oracle impdp (data pump) to escape/include few tables.
The following code shows how they can be used as command line parameters.
impdp scott/tiger#db10g schemas=SCOTT exclude=TABLE:"IN ('EMP', 'DEPT')" directory=TEST_DIR dumpfile=SCOTT.dmp logfile=expdpSCOTT.log
Same can be done during export as well:
expdp scott/tiger#db10g schemas=SCOTT exclude=TABLE:"IN ('EMP', 'DEPT')" directory=TEST_DIR
CONTENT=METADATA_ONLY switch should be used if you indeed want to create structure on target schema/db.
Q.2:
You can not use expdp / impdp on a different SID as is but via DB Link route (using NETWORK_LINK switch).
However, i think, Ans-1 should address your real problem due to Oracle XE limitations. Moreover, there may be performance issues due to cross network/DB data flow.
Both the local and remote users require the IMP_FULL_DATABASE role granted to them.
impdp test/test#db10g tables=SCOTT.EMP network_link=REMOTE_SCOTT directory=TEST_DIR logfile=impdpSCOTT.log remap_schema=SCOTT:TEST
HTH
Check the following for more options with data pump:
http://www.oracle-base.com/articles/10g/oracle-data-pump-10g.php
I have created a PostgreSQL database dump using psql.
Now I want to restore this backup from the file:
psql -d thesamename -f /my/backup/file
But I get errors that the data already exists.
Is there any command to delete everything from the database to bring it to just created state, except dropping and creating once again?
(I don't want to set up owner, tablescpace etc. once again)
Maybe some way to overwrite the database with the one from the backup file? (the backup file is from another database server)
https://www.postgresql.org/docs/current/static/app-pgdump.html
https://www.postgresql.org/docs/current/static/app-pgrestore.html
Have a look specifically at the -c option for these scripts.
You can drop the public schema of your database and re create it after :
DROP SCHEMA PUBLIC CASCADE;
CREATE SCHEMA PUBLIC AUTHORIZATION postgres;
GRANT ALL ON SCHEMA public TO public;
Hope it helps…
you can manipulate it as you want..and you want only dumping of data.once you will start to dumping data schema file will generate automatically.and no need to drop old data.it will overlap with new data over existing data.
You can go through this link for more clarification..
http://www.postgresql.org/docs/8.4/interactive/app-pgdump.html
http://www.postgresql.org/docs/8.4/interactive/app-pgrestore.html
You can use
GRANT ALL ON SCHEMA public TO public;
I'm searching for a simple way to delete all data from a database and keep the structure (table, relationship, etc...).
I using postgreSQL but I think, if there a command to do that, it's not specific to postgres.
Thanks,
Damien
Dump the schema using pg_dump. drop the database, recreate it and load the schema.
Dump you database schema (the -s tag) to a file:
pg_dump -s -f db.dump DB-NAME
Delete the database:
dropdb DB-NAME
Recreate it:
createdb DB-NAME
Restore the schema only:
pg_restore db.dump > psql DB-NAME
This should work on PostgreSQL; Other DBMS might have their own tools for that. I do no know of any generic tool to do it.
EDIT:
Following comments, you might want to skip the dropdb command, and simply create another database with the dumped schema. If all went through well, you can drop the old database:
pg_dump -s -f db.dump DB-NAME
createdb DB-NEW-NAME
pg_restore db.dump > psql DB-NEW-NAME
At this point, you have the full database at DB-NAME, and an empty schema at DB-NEW-NAME. after you're sure everything is OK, use dropdb DB-NAME.
You can do something like this:
export PGUSER=your_pg_user
export PGHOST=database.host
export PGPORT=port
export PGDATABASE=your_database
psql -qAtX -c "select 'TRUNCATE table ' || quote_ident(table_schema) || '.' || quote_ident(table_name) || ' CASCADE;' from information_schema.tables where table_type = 'BASE TABLE' and not table_schema ~ '^(information_schema|pg_.*)$'" | psql -qAtX
It will do what's necessary.
Of course these exports are not necessary, but they will make it simpler to run 2 copies of psql without having to givem them all standard -U, -d, and so on, switches.
One thing though - using TRUNCATE to do so, while faster than DELETE, has it's drowbacks - for example - it is not being replicated by Slony and any other replication system that works on triggers. Unless you are working on PostgreSQL 8.4, and your replication knows how to use triggers on TRUNCATE.
I'm not a Postgres guy, but one option would be to iterate through the tables and issue a Truncate command against each one. You'll have to take otable relationships into account, though - you will not be able to delete reference data before data that refers to it, for example.
In pgAdmin you can do:
Right-click database -> backup, select "Schema only"
Drop the database
Create a new database and name it like the former
Right-click the new database -> restore -> select the backup, select "Schema only"
your can delete all records of your database without restriction of foreign keys by following three steps
Take script of your Database
Right Click on your database (your DB Name)
click on task and then "Generate script"
Specify location
Delete your database base
recreate a database with the same name and run you generated script
This way you can empty all of your database