Notes on common DB/Linux Commands

Source: Internet
Author: User
Tags dedicated server
Notes for common DB/Linux commands 1 UserGroup/etc/passwd: username: passwd: uid: gid: homedir: shell password ing in/etc/shadow, A user can belong to multiple user groups. The Fifth Field is the full name of the user name (optional)/etc/group: grou... notes for common DB/Linux commands 1 UserGroup/etc/passwd: username: passwd: uid: gid: homedir: shell password ing in/etc/shadow, A user can belong to multiple user groups. The Fifth Field is the full name of the user name (optional)/etc/group: groupname: passwd: gid: userlist. the user list is optional. "Split 2 AddUser & Group ● modify file more/etc/passwd | grep oracle cat/etc/group | grep uid modification Passwd: Add user records, so that the uid cannot be repeated. execute pwconv to synchronize passwd and shadow. modify the group and add group to run the "maid" command to synchronize group and shadow. create the user's home directory, copy the user's startup file. In addition, you also need to copy the files in the etc/skel directory. * copy the hidden File: cp-R/etc/skel/home/user; change the owner and permissions of the new user: chown-R user: group/home/user; -R: apply all files in the directory? Set the new user password: passwd username ● run the command 1) mkgroup groupname 2) groupadd-g uid groupname 3) mkuser mkduer pgrp = username home = diracw.shell =/usr/bin/ksh id = uid username 4) useradd-u 1002-g group-G group01-d/home/user-m user useradd-d/opt/oracle-m-g dba-G oinstall-s/bin/ bash oracle user's default working directory is/home/username, you can use-d to specify other directories as their working directories. the user's default uid is increased from 500 to the later order. you can use-u to specify the uid. the user's group is not specified, A job with the same name as the user name is generated. Group, you can also use-g to specify 5) ld, finge to view user information 6) ls-dl $ HOME to display the owner and Group of the Directory 7) usermod: modify Usermod-l newname oldname; modify usermod-d newdir user; add user to group usermod-g group user; differences between small G and large g 8) gpasswd changes the group members. only the root and group administrators have the permission to add: Gpasswd-a user group delete: Gpasswd-d user group 9) Groupmod modifies the group name: groupmod-n oldname newname 10) rmuser-r username 11) Userdel delete a user and delete the working directory userdel-rf user 12) Rmgroup-rgroupname 13) Gro Updel 3 common Linux commands: tar-cvf-file | gzip-cf> file.tar.gz gzip-dc file.tar.gz | tar-xvf-gunzip directly decompress the gz package unzip (zip) directly decompress the zip package mv origfile destfile to cut the content in the source file to the target folder find. -name "*. log "| xargs rm | awk '{print $2}' | xargs kill-9 or | awk '{print" kill-9 ", $2} 'df-h; fdisk-l shows the disk space du-lh du-sh * Java-version Version. check the Uname-a model or oslevel operating system version of the sh platform: # Check the kernel version of cat/etc/SuSE-release: # Uname-r4 environment variable setting # echo $ SHELL bash: # vi. bash_profile #.. bash_profile sh or ksh: # vi. profile #.. profile csh or tcsh: # vi. login # source. login. cshrc? Setenv var = xxx; export var xxx; # echo $ JAVA # env | the grep JAVA shell type does not match. The other ln shell types to the current -- ln-s src desc script executes bash: #. /script; ksh: # sh script; bash-> ksh? = JAVA = root user upload (. bin ,. rpm, compressed package), set to use the user's environment variable export JAVA_HOME =/opt/jdk1.6 export JRE_HOME =/opt/jdk1.6/jre export CLASSPATH = $ JAVA_HOME/lib: $ JRE_HOME/lib :. export PATH = $ JAVA_HOME/bin: $ JRE_HOME/bin: $ ORACLE_HOME/bin :.: $ PATH = ORACLE = patch installation-Ora software installation-configuration listening-upgrade Ora-create DB export ORACLE_BASE =/opt/oracle/app/oracle export ORACLE_HOME = $ ORACLE_BASE/product /11.2.0/dbhome_1 export ORACLE_SID = SID export PATH = $ ORACLE_HOME/bin: $ PATH 5 Oracle1) Dbca creates database (instance) instances as "memory" (SGA) and "background process" (server process, background process, and subordinate process) each process allocates internal memory (PGA memory) to complete its task RAC (Real Application Cluster) Cluster: multiple instances drive a database at the same time. 2) $ TNS_ADMIN specifies the configuration file tnsnames. ora location: $ ORACLE_HOME/network/admin Tnsnames. ora storage network service name (set as SIDname, as the alias of the connection descriptor) file structure: Esbora = (DISCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = IP) (PORT = 1521) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = Esbora) (3) client connection database connection string Sqlplus user/pwd @ HOSTIP: 1521/SID network string Sqlplus user/pwd @ netservicename native login does not need to input @ nsn Sqlplus sys/sys as sysdba or sqlplus "/as sysdba" Sqlplus/holog no user connects to DB Conn user /pwd @ nsn @ execute the specified directory script Disc disconnect 6 Listener1) clinet -- Listener -- Server 2) Netca configuration listener on the Server side 3) Listener configuration file $ TNS_ADMIN/listener. ora file structure: LISTENER = LISTENER name, default LISTENER (DISCRIPTION_LIST = (DISCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = IP) (PORT = 1521) (ADDRESS = (PROTOCOL = IPC) (KEY = EXTPROC1521 )))) SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = esbora) (ORACLE_HOME =/opt/oracle/app/oracle/OraHome_1) (PROGRAME = extproc) 4) lsnrctl start (ListenerName) without adding a name to start listening by default 5) Lsnrctl stop 6) Lsnrctl status 7 database installation patch installation-Ora software installation-configuration listening-upgrade Ora-create DB sequence? ● Set the Display variable Xmanager to log on to the Root: xhost localhost directly with the oracle User; xhost + open all Oracle: export DISPLAY = localhost: 1.0 setenv DISPLAY local_host: 0.0 echo $ DISPLAY xclock path/usr/X11R6/bin can be added to the environment variable ● install the patch and install the database, and then install the database in the patch directory oui/bin /. /runInstaller if the database installation directory is not in the patch Directory, for example, if the patch directory is OraHome_1 and OraHome_2, you must enter the $ ORACLE_HOME directory as an oracle user, make the jdk directory mv jdk. run the following command to create a link: # ln-s/opatch_path/jdk # ls-al: jdk-> opt/oralce/app/oracle/OraHome_1/jdk 8 system management 1) database Startup: log on to Startup nomount as sysdba. only start the instance. do not start the database. starting the instance includes allocating memory and starting the process (reading the parameter file). Startup mount starts the database to the mount state (including nomount) open the control file, data file, and on-line log file, and associate the instance Alter database open to open the database ● Startup; use the server-side parameter file (SPFILE) to start the instance. do not add SPFILE; you can also use the initialization parameter file (PFILE) to start: startupPFILE = $ ORACLE_HOME/dbs/init. ora Startup open read only starts the database in read-only mode. ● Nomount-> alter database mount-> alter database open; ● Mount-> alterdatabse open; Alter database open readonly; in the mount status, start in read-only mode. FAQ: database startup is suspended. AlterFile: The Flash Recovery Area has insufficient disk space. PFILE contains the path and size of the Flash Recovery Area. Db_recovery_file_dest =' /Flash_recovery_area 'db_recovery_file_dest_size = 2G 2) close the database (write data files and connection logs)-> Unmount the database (detach the database and instance, and disable the control file) -> shut down the instance (removing the SGA from the memory and terminating the process) and shut down the immediate user. the user cannot register and log on. events that have not been submitted are rolled back in Jiangbei district; there are two types of process management processes that do not wait for all users to exit 9: User process and oracle Process 1) when a user process user runs an application or uses an oracle client, two similar concepts are created: ● connection: A communication path between a user process and an instance. generally, a dedicatedserver connection is established between the customer process and a dedicated server or a scheduler, when a VPC connection is used, a dedicated process for the connection will be obtained on the server. there is a one-to-one ing between the database connection and a process or thread on the server (sh) When a shared connection is used, multiple sessions can share a server progress pool. the processes are generated and managed by the Oracle instance, you are connected to a database scheduler (dispatcher), instead of a dedicated server process specially created for the connection. ● Session: a special connection from a user to a database, starting from user login to exit. a session is a logical entity in the instance. the customer process can execute SQL statements on the session, commit transactions and run stored procedures. Multiple independent sessions can be associated with one connection. These session settings can exist independently of the connection. 2) Oracle Process (instance process) the Oracle process runs on the server: ● server process (ServerProcess): the server process is a process that completes the work on behalf of the customer session to process user process requests connected to the database, perform syntax parsing and execution on SQL statements, read data, and return results: VPC process (Dedicated): Service sharing server process (Shared) only for specific user processes ): when a server process is shared, multiple sessions can share a server process Pool. the processes are generated and managed by the Oracle instance. ● BackgroundProcess: starts with the database, used to complete various maintenance tasks 10 data storage structure ● logical structure (LogisticalStructure): Data Block (DataBlock) area (Extent) Segment (Segment) table space (Tablespace) block is the most basic storage unit tablespace: stores database objects (tables, indexes, etc.) ● physical structure (PhysicalStr Ucture): Datafiles, Control Files, Online Redo Logs (strictly) other Archive Log Files, Parameter Files, AlertFiles, Trace Files, Backup Files DataFiles: each data file is an operating system file consisting of multiple operating system blocks. the table and index data in the database are physically stored in the data file. a database has multiple data files, A data file only belongs to one database and one tablespace can be composed of multiple data files. a data file only belongs to one tablespace) create tablespace tibco datafile '/home/oracle/ora/oradata/VERIFY111/tibcodata1.dbf' SIZE 2048 m reuse autoextend on next 100 M MAXSI ZE20480M, '/home/oracle/ora/oradata/VERIFY111/TIBCODATA2.DBF' SIZE 2048 m reuse autoextend on next 100 M MAXSIZE20480M, logging extent management local segment space management auto; 2) create user tibapp Identified by tibapp Default tablespace TIBCODATA Temporary tablespace TEMP Profile DEFAULT; -- Grant/Revoke role privileges Grant connect to tibapp; Grant resource to tibapp; -- Grant/Revoke syst Em privileges Grant unlimited tablespace to tibapp; 3) delete tablespace and user Spool. /log/delete_tbs_user.log Connect sys/sys@10.71.179.64/eplus11 as sysdba Drop user username cascade; -- cascade indicates to delete the object Drop tablespace TIBCODATA in this user mode before deleting the user; Spool off Exit; 4) common SQL ● Select open_mode from v $ database Select status from v $ instance ● tablespace, data file Select * from dba_tablespaces; Select username, default_tablespace f Rom dba_users where username = ''; user's default tablespace --------- query table space size --------- selectb. file_id File ID, B. tablespace_name tablespace name, B. bytes/1204/1204 | 'M', (B. bytes-sum (nvl (. bytes, 0)/1024/1024 | 'M' used, sum (nvl (. bytes, 0)/1024/1024 | 'M' remaining space, 100-sum (nvl (. bytes, 0)/(B. bytes) * 100% occupied by fromdba_free_space a, dba_data_files B wherea. file_id = B. file_id groupby B. tablespace_name, B. file_id, B. bytes order by B. file _ Id --------- modify the tablespace size --------- alter database datafile 'datafile _ path/dbfname' resize1024M; alter tablespace tbsname add datafile '*** 'size 500 m autoextend off; ● user management select username from dba_users; select username, default_tablespace from dba_users where username = ''; alter user username identified by new password; ● process query the process ID (PID) associated with the VPC Select. spid dedicated_server, B. processclientpid From V $ process a, v $ session bwhere a. addr = B. paddr And B. sid = (select sid fromv $ mystat where rownum = 1); Sqlplus :! /Bin/ps-p pid View process ID corresponding information background process View Select * from v $ bgprocess where paddr <> '00 '; ps-ef | grep ora _ ● killing user processes (session sessions) Select sid, serial #, username, status, server, process, osuser, paddr fromv $ session where type = 'user'; Process: clientpid paddr: VPC Process address Alter system kill session 'Sid, Serial #'; --------- tracing method --------- query the session information of oracle users: select username, machine, osuser, programe, status, count (machine) fromv $ session where username = ''group by username, machine, programe, status, osuserorder by username, machine; find the oracle connection client, find the process connecting to the oracle user source to kill ● database backup a) Exp user/pwd @ SID owner: user rows = y compress = n buffer = 65536 feedback = 100000 volsize = 0 file = user. dmp log = user. log; B) Expdp user/pwd @ SID directory = dir_name dumpfile = user. dmp schemas = user logfile = user. log; query the create db directory Select * from dba_directories; Createdirectory dir_name as 'dir _ path'; Grantread, write or directory dir_name to public; ● time Select to_char (B2C (req_message )) from table where instr (B2C (req_message), 'str')> 0; Selet cast (sysdate as timestamp) "DATE" from dual; Select to_char (sysdate, 'yyyymmdd24miss ') from dual; Select to_char (to_date ('2017-06-30 15:15:15 ', 'yyyy-mm-ddhh24: mi: SS'), 'yyyy-mm-dd am hh24: mi: ss ') from dual; Select to_date (to_char (sysdate, 'yyyy-mm-dd hh24: mi: SS'), 'yyyy-mm-ddhh24: mi: SS') from dual; select to_number (to_char (sysdate, 'yyyymmdd') from dual; Select to_date ('2017-1-1 ', 'YY-mm-DD') from dual; l Select to_date (sysdate) from dual; Select sysdate-1 from dual; Select add_months (sysdate,-1) from dual; Select sysdate-1/(24*60) from dual;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.