In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces which oracle commands are commonly used in the linux system, the article is very detailed, has a certain reference value, interested friends must read it!
Oracle database system is a popular relational database management system in the world at present. The system has good portability, easy to use and strong function, and is suitable for all kinds of large, medium, small and microcomputer environments. It is a database solution with high efficiency and good reliability, which adapts to high throughput.
I. commands for oracle to build and delete databases
(1) build oracle11g database (it is customary to configure gdbname is the same as sid name, and sys password is the same as system password to facilitate memory)
[oracledb@] $dbca-silent-createDatabase-templateName / u01/oracle/product/11.2.0/dbhome_1/assistants/dbca/templates/General_Purpose.dbc-gdbname GDBNAME-sid SIDNAME-characterSet AL32UTF8-NATIONALCHARACTERSET UTF8-sysPassword SYSPASSWORD-systemPassword SYSTEMPASSWORD-TOTALMEMORY 2048
Method 1 for deleting the library:
[oracledb@] $dbca-silent-deleteDatabase-sourceDB SIDNAME-sysDBAUserName sys-sysDBAPassword SYSPASSWORD
Delete library method 2:
# step 1: configure the response file:
[oracledb@ ~] $cat / u01/oracle/response/dbca.rspOPERATION_TYPE = "deleteDatabase" SOURCEDB = "SIDNAME" SYSDBAUSERNAME = "sys" SYSDBAPASSWORD = "SYSPASSWORD"
# step 2: perform deletion of response file:
[oracledb@ ~] $dbca-silent-responseFile / u01/oracle/response/dbca.rsp
(2) Building oracle12c database
[oracledb@] $dbca-silent-createDatabase-templateName / u01/oracle/product/orahome/assistants/dbca/templates/General_Purpose.dbc-gdbname GDBNAME-sid SIDNAME-characterSet AL32UTF8-NATIONALCHARACTERSET UTF8-sysPassword SYSPASSWORD-systemPassword SYSTEMPASSWORD-TOTALMEMORY 2048
# the deletion command is the same as above. Note that after running the delete command, you need to delete the remaining directories manually.
(3) deletion usually automatically deletes the library information in the following path or file
A:/u01/oracle/admin/SIDNAMEB:cat / etc/oratabC:/u01/oracle/oradata/SIDNAME
The following paths need to be manually cleaned
SIDNAMEE _ SIDNAME _ data _ two, create the corresponding account password of the database.
1. Switch SID
[oracledb@ ~] $export ORACLE_SID=SIDNAME
2. Switch character set
# View the character set of oracle database
SQL > select userenv ('language') from dual
# View the encoding of the oracle database
SQL > select * from nls_database_parameters where parameter = 'NLS_CHARACTERSET'; [oracledb@ ~] $set NLS_LANG=AMERICAN_AMERICA.AL32UTF8 # windows_ os [oracledb @ ~] $export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 # linux_os
3. Create the user information corresponding to the library
SQL > create temporary tablespace SIDNAME_temp tempfile'/ u01/oracle/oradata/SIDNAME/SIDNAME_temp.dbf 'size 64m autoextend on next 64m maxsize unlimited extent management local;SQL > create tablespace SIDNAME_data logging datafile' / u01 maxsize oradata size SIDNAME maxsize 64m maxsize 2048m extent management local;SQL > create user USERNAME identified by USERPASSWORD default tablespace SIDNAME_data temporary tablespace SIDNAME_temp;SQL > grant connect,resource to USERNAME;SQL > grant create view to USERNAME;SQL > grant unlimited tablespace to USERNAME;SQL > grant create public synonym to USERNAME;SQL > grant drop public synonym to USERNAME SQL > create or replace directory dir_dump as'/ u01According to oracle, grant read,write on directory dir_dump to USERNAME;SQL > ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED
-modify processes and sessions parameter values according to the instance environment (oracle database needs to be restarted)
SQL > alter system set processes=1000 scope=spfile; SQL > alter system set sessions=1105 scope=spfile
Knowledge points:
The definition of the oracle11g:sessions value should be greater than or set to 1.1processes+5, and if it is less than 1.1processes+5, oracle automatically sets this parameter to 1.1processes+5 at startup. This is mainly due to the session initiated by the background process and about 10% of the recursive session.
Oracle12c:1.1processes+22
# # query the number of concurrent connections to the current oracle:
SQL > select count (*) from v$session where status='ACTIVE'
# check the number of connections of different users:
SQL > select username,count (username) from v$session where username is not null group by username
# View all users:
Select * from all_users
# current number of connections
Select count (*) from v$process
# maximum number of connections allowed in the database
Select value from v$parameter where name = 'processes'; III. Database restore and backup commands
View the expdp export backup storage path:
Sql > select * from dba_directories
1. Backup and restore operations for the entire library
(1), database backup (note that sometimes SIDNAME and SCHEMASNAME are not consistent, pay attention to the distinction when using, general configuration of the same name, easy to remember, but also convenient for operation and maintenance. The parallel parameter adds a reasonable value according to the configuration of server memory and so on.)
# backup:
[oracledb@ ~] $expdp USERNAME/USERPASSWORD@SIDNAME schemas=SCHEMASNAME dumpfile= SIDNAME`date +% Y% m% d`.dmp directory=dir_dump parallel=2
twelve
(2), restore
Case 1. The instance name of the original database is different from that of the target database (note that the data tablespace name of some environments is not SIDNAME_data, please verify when using it)
# format:
[oracledb@ ~] $impdp USERNAME/USERPASSWORD@SIDNAME schemas=SCHEMASNAME DUMPFILE=XXXX.dmp DIRECTORY=dir_dump remap_schema= source SCHEMASNAME: destination SCHEMASNAME remap_tablespace= source _ data: destination _ data
Case 2: the source database has the same instance name as the destination database
# format:
[oracledb@ ~] $impdp USERNAME/USERPASSWORD@SIDNAME schemas=SCHEMASNAME DUMPFILE=XXXX.dmp DIRECTORY=dir_dump EXCLUDE=STATISTICS
Knowledge expansion: excluding statistics when using EXCLUDE=STATISTICS restore, you can use the following command to complete statistics
# the command is as follows:
SQL > exec dbms_stats.gather_schema_stats (ownname= > 'SIDNAME',estimate_percent= > 10 ALL' degree = > 8 charge cascadeo > true,granularity= >' ALL')
2. Backup and restore operations for single table
(1) backup list table
Format:
[oracledb@ ~] $expdp USERNAME/USERPASSWORD@SIDNAME dumpfile=tablenameXXXX.dmp DIRECTORY=dir_dump tables=TABLENAME
(2) restore single table
# format:
[oracledb@ ~] $impdp USERNAME/USERPASSWORD@SIDNAME dumpfile=tablenameXXXX.dmp DIRECTORY=dir_dump TABLES=TABLENAME TABLE_EXISTS_ACTION=REPLACE
Extensions: table_exists_action parameter description
When using imp for data import, if the table already exists, drop the table first, and then import it. When using impdp to complete database import, if the table already exists, there are four processing methods: parameter (1) skip: default operation parameter (2) replace: first drop table, then create table, and finally insert data parameter (3) append: add data parameter to the original data (4) truncate: first truncate, then insert data (3) backup multiple tables
# format:
[oracledb@ ~] $expdp USERNAME/USERPASSWORD@SIDNAME dumpfile=tablenameXXXX.dmp DIRECTORY=dir_dump TABLES= source TABLENAME1, source TABLENAME2,.
(4) restore multiple tables
# format:
[oracledb@ ~] $impdp USERNAME/USERPASSWORD@SIDNAME dumpfile=tablenameXXXX.dmp DIRECTORY=dir_dump remap_table= source TABLENAME1: destination TABLENAME11 TABLE_EXISTS_ACTION= replacement [oracledb @ ~] $impdp USERNAME/USERPASSWORD@SIDNAME dumpfile=tablenameXXXX.dmp DIRECTORY=dir_dump remap_table= source TABLENAME2: destination TABLENAME22 TABLE_EXISTS_ACTION=REPLACE
3. Expand knowledge
1) expand 1:
Case 1. When restoring an export from a higher version to a lower version, such as from 12 to 11, add the version number of the lower version version=11.1.0.2.0 when the export is performed at 12c
# format:
[oracledb@ ~] $expdp USERNAME/USERPASSWORD@SIDNAME schemas=SCHEMASNAME dumpfile=XXX.dmp DIRECTORY=dir_dump version=11.1.0.2.0
Case 2. When restoring a lower version to a higher version, the higher version is generally compatible with the lower version. At present, there is no problem with restoring 11 to 12 in personal operation and maintenance work.
2) extension 2:
(1) backup according to the specified size, such as 5G per copy (parallel is multithreaded, the number of threads is less than the number of files generated, and the number of threads is less than the number of cpu threads)
# backup format
[oracledb@ ~] $expdp USERNAME/USERPASSWORD@SIDNAME schemas=SCHEMASNAME DIRECTORY=dir_dump dumpfile=XXX_%U.dmp logfile=expdpXXX.log filesize=5G parallel=16
(2) restore multiple backup files:
# restore format
[oracledb@ ~] $impdp USERNAME/USERPASSWORD@SIDNAME schemas=SCHEMASNAME DIRECTORY=dir_dump dumpfile=XXX_%U.dmp logfile=impdpXXX.log parallel=16
3) extended 3 Export filtering does not export a table:
# format
[oracledb@ ~] $expdp USERNAME/USERPASSWORD@SIDNAME schemas=SCHEMASNAME DIRECTORY=dir_dump dumpfile=XXX.dmp exclude=TABLE:\ "IN\ 'TABLENAME\"
4) extension 4 when restoring different libraries, do not change the data structure and use truncate parameters:
# format
[oracledb@ ~] $impdp USERNAME/USERPASSWORD@SIDNAME schemas=SCHEMASNAME DIRECTORY=dir_dump dumpfile=XXX.dmp remap_schema= source SCHEMASNAME: destination SCHEMASNAME remap_tablespace= source _ data: destination _ data TABLE_EXISTS_ACTION=truncate
5) expand 5. Keep the table when exporting the backup and clear the table data (query parameter):
# format
[oracledb@] $expdp USERNAME/USERPASSWORD@SIDNAME schemas=SCHEMASNAME DIRECTORY=dir_dump dumpfile=XXX.dmp logfile=expdpXXX.log query=TABLENAME1:' "where 1: 2", TABLENAME2:' "where 1: 2",.
6) extension 6 preserve tables when exporting backups, clear table data, and filter two tables at the same time
# format
[oracledb@ ~] $expdp USERNAME/USERPASSWORD@SIDNAME schemas=SCHEMASNAME DIRECTORY=dir_dump dumpfile=XXX.dmp logfile=expdpXXX.log query=TABLENAME1:' "where 1: 2", TABLENAME2:' "where 1: 2" 'exclude=TABLE:\ "IN\' TABLENAME1\'\ 'TABLENAME2\'\"
7) extension 7 only counts the data of each table in the database, but does not export, parameter estimate_only=y
# format
[oracledb@ ~] $expdp USERNAME/USERPASSWORD@SIDNAME schemas=SCHEMASNAME DIRECTORY=dir_dump estimate_only=y
8) expand 8 to import a single table into a temporary table:
# format (adding parameter EXCLUDE=STATISTICS EXCLUDE=INDEX when involving statistics and indexing)-sql implementation to copy from this table to another temporary table
SQL > CREATE TABLE destination TABLENAME AS (SELECT * FROM source TABLENAME)
-clear the data in the table
SQL > delete from destination TABLENAME
[oracledb@ ~] $impdp USERNAME/USERPASSWORD@SIDNAME DIRECTORY=dir_dump DUMPFILE=tablenameXXX.dmp remap_table= source TABLENAME: destination TABLENAME TABLE_EXISTS_ACTION=REPLACE EXCLUDE=STATISTICS EXCLUDE=INDEX [oracledb@ ~] $expdp USERNAME/USERPASSWORD@SIDNAME schemas=SCHEMASNAME ESTIMATE_ONLY=y NOLOGFILE=y FULL=y
9) extension 9 the content of individual sql scripts is very long, and it will always be stuck when executing with PLSQL Developer tools. When there is no response, in addition to using PLSQL Developer tools to execute in the command window, you can also use shell terminals to execute.
# format
[oracle@localhost ~] $export ORACLE_SID= SIDNAME [Oracle @ localhost ~] $sqlplus / as sysdbasql > conn USERNAME/USERPASSWORD@SIDNAMEsql > @ / u01/oracle/backup/XXX.sql
10) extension 10 how to correctly terminate expdp and impdp tasks, the steps are as follows:
Step 1. View the view dba_datapump_jobs
Select job_name,state from dba_datapump_jobs
Step 2. Stop the expdp export task correctly and use stop_job
Expdp USERNAME/USERPASSWORD@SIDNAME attach=SYS_EXPORT_SCHEMA_02
Step 3. Stop the task
Export > stop_job=immediateAre you sure you wish to stop this job ([yes] / no): yes
Step 4. View the backup job status on the system
Select owner_name,job_name, state from dba_datapump_jobs
Extension: the following commands are valid in interactive mode:
HELP: summarize interactive commands. KILL_JOB: detach and delete jobs. PARALLEL: changes the number of active worker for the current job. PARALLEL=.2START_JOB: starts / resumes the current job. START_JOB=SKIP_CURRENT skips any actions performed when the job stops before starting the job. STATUS: the frequency (in seconds) of the job status to be monitored when the default value (0) displays the new status when available. STATUS [= interval] STOP_JOB: sequentially closes the executed job and exits the client. STOP_JOB=IMMEDIATE will immediately close the data pump job.
11) extension 11
# check the value of NLS_CHARACTERSET in DB
SQL > select * from v$nls_parameters where parameter='NLS_CHARACTERSET';SQL > select * from nls_database_parameters t where t.parameterized
12) extension 12 about exp, imp, expdp, impdp
(1) exp and imp are client-side tool programs that can be used either on the client side or on the server side. (2), expdp and impdp are server-side tools, they can only be used on the oracle server, not on the client. (3) imp only applies to exp exported files, not expdp exported files; impdp only applies to expdp exported files, not exp exported files. (4) for servers with more than 10g, it is usually not possible to export empty tables with 0 rows of data using exp, but expdp must be used to export at this time. 13) when the 13oracle user password has the @ symbol, expdp connects with sqlplus and uses rar to compress the backed up files.
@ echo offrem-dmp backup directory, same as dump dirset backup_dir=e:\ app\ oracle\ backuprem-today Day for dmp file remainingset day=%date:~0,4%%date:~5,2%%date:~8,2%set remain_day=7rem-delete files before 7 daysforfiles / p "% backup_dir%" / d -% remain_day% / c "cmd / c del / f @ path" rem-export oracle data to dmp fileexpdp username /\ "xxx@yyy\" @ orcl directory=dir_dump dumpfile= username _% day%.dmp logfile= username _% day%.log schemas= username parallel=4 compression=ALLrem-sqlplus Connsqlplus user name / "xxx@yyy" @ orclrem-if compress the dumpfile and delete source dumpfile Unmark remset rar= "C:\ Program Files (x86)\ WinRAR\ WinRAR.exe"% rar% a-df% backup_dir%\ username _% day%.rar% backup_dir%\ username _% day%.dmp% backup_dir%\ username _% day%.log IV, cleanup (error in restore Clear user tablespace)
1. Delete the data tablespace:
# execute statement:
[oracledb@ ~] $sqlplus / as sysdbaSQL > drop tablespace mepro_data including contents and datafiles cascade constraint
2. Delete temporary tablespace:
# execute statement:
SQL > drop tablespace mepro_temp including contents and datafiles cascade constraints
3. Delete the user:
# execute statement:
SQL > drop user srmhdld cascade
4. Report that the user is connecting and cannot delete the solution.
-method 1: restart and execute the drop user statement quickly (personal recommendation)
SQL > shutdown immediate;SQL > startup
-method 2: delete the connected session (the connected session is connected for a long time, cleaning is time-consuming, and method 1 is not fast) # query the user session
SQL > select username,serial#,sid,program,machine,status from v$session where username='USERNAME' AND STATUS='ACTIVE';;SQL > select saddr,sid,serial#,paddr,username,status from v$session where username is not null
-Delete related user session
SQL > alter system kill session 'serial#, sid'; are all the contents of this article entitled "what are the common oracle commands in linux systems?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.