PostgreSQL Commands

connect into postgres(default) database:

psql –U postgres

connect other db server in command prompt:

set PGPASSWORD=XXX
psql -h hostname -p 5432 -d databaseName -U userName -W

https://stackoverflow.com/questions/32824388/postgresql-remotely-connecting-to-postgres-instance-using-psql-command

show installed locale:

SHOW LC_COLLATE

making backup file:

pg_dump -U postgres SID/database/server's name> dbexportname.pgsql

backup by tar file(better for binary data):

pg_dump -U [yourUserName] -h [yourHostName] -F t -f xxx.tar [yourDataBaseName]

restore by tar file:

pg_restore -U [yourUserName] -h [yourHostName] -d [yourDatabaseName] -F t xxx.tar

restore from dump file:

psql -U accountName databaseName < backupName.pgsql

list all database:

\l

check databasename:

\db+

show main data directory:

show data_directory;

check password lifetime:

https://www.modb.pro/db/103980#51_pg_userpg_authidpg_rolespg_auth_members_305

\d pg_user

check the user’s capacity:

select * from pg_user where usename='yourUserName';

select * from pg_authid;

select * from pg_authid where rolvaliduntil is null;

pset null ‘null’;

select rolename,rolvaliduntil from pg_authid;

check the charactor code:

show server_encoding;

clear screen:

\! cls

use db account postgres to log into the spotfire_server db:

psql -d spotfire_server -U postgres

check postgreSQL version:

psql -V

check settings like:

select setting from pg_settings where name='port';

https://qiita.com/awakia/items/9981f37d5cbcbcd155eb

List all tables in postgresql information_schema:

https://stackoverflow.com/questions/2276644/list-all-tables-in-postgresql-information-schema

select * from pg_tables where schemaname = 'information_schema';

create a database without dbcreate privilege and user:

eg:

createuser spotfire_joindb with password 'spotfire' nocreatedb;
create database spotfire_joindb;
alter database spotfire_joindb owner to spotfire_joindb;

check the os: select version();

calculate row size of postgres table row:

https://stackoverflow.com/questions/34222996/how-to-get-each-row-size-of-a-particular-table-in-postgresql?answertab=active#tab-top

SELECT sum(pg_column_size(t.)) as filesize, count() as filerow FROM tableName as t;

check the column’s data type:

select pg_typeof(colName) from tableName;

show the data table in a certain database:

\dt

delete table:

DROP TABLE test;

delete database:

drop database databaseName;

Change default PostgreSQL passwords

cancel peer authentication:

change the content in /etc/postgresql/13/main/pg_hba.conf as below:

# "local" is for Unix domain socket connections only
local   all             all                                     md5

set listen inbound port:

change the content in /etc/postgresql/13/main/postgresql.conf:

listen_addresses = '*'               # what IP address(es) to listen on;

set inbound IP address:

change the content in /etc/postgresql/13/main/pg_hba.conf:

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             192.168.1.0/24            md5

PostgreSQL data file folder: show data_directory;

Linux

solve the internet connection problem:https://geekflare.com/no-internet-connection-from-vmware-with-centos-7/

dhclient -v

to command mode:

Ctrl+Alt+F2

clean the screen:

clear

synchronize data on disk with memory:

sync

show all the files under a folder:

ls -alht

ls -alht --time-style=+'%Y/%m/%d %H:%M:%S'

set in .bashrc: alias ll="ls -alht --color=auto --time-style=+'%Y/%m/%d %H:%M:%S'"

https://traincat.net/blog/neko/archives/000334.html

ls -l --full-time

ls -l /

show folder xx*:

ls -ld *

check how many files in a folder linux:

ls -l . | egrep -c '^-'

ls -1 | wc -l

check the ip address:

ifconfig -a

ip a

ip r | grep default

look the previous page:

SHIFT+PGUP

ping IP address:

ping -4 DESTINATION

open vi:

/bin/vi xxx.txt

check the format of file in \r or \n:

in vim: :set ff?

change color to be easily seen:

:color ron

change it to unix: :set ff=unix

clear all the firewall rules: https://www.shuzhiduo.com/A/gAJGaeyndZ/

iptables -F

check Linux version:

cat /etc/redhat-release

cat /etc/os-release

lsb_release -a

check the kernel of Linux: uname -r

show system information: uname -a

show current path(not shortcut, the real place):

pwd -P

read, write and executable:

sudo chmod 777 filename

zip a folder:

zip -r temp.zip ./temp/

make a new directory:

mkdir -p parent/son
mkdir -m 711 xxx
move/rename folder:
mv folderName newFolderName
check memory state:
cat /proc/meminfo
check cpu information:
lscpu | egrep 'Model name|Socket|Thread|NUMA|CPU\(s\)'
show current time:
date +%Y/%m/%d
date +%H:%M
date '+%F'
date
poweroff Linux:
/sbin/shutdown -h now
1 min later:
/sbin/shutdown -h 1
/sbin/shutdown -h 10:33
cancel it:shutdown -c
reboot now:
reboot
/sbin/shutdown -r now
users' home folder is located in:
~ means /home/xxx
but root's home is in /root
file with . prefix can be a hidden file.
eg: .bash_profile
open GNOME,KDE,TWM:
startx
logout: exit(ctrl+d)
check calendar:
cal 06 2021
calculator:
bc
echo "1+35" | bc
scale=number, number after the decimal point
quit to exit
get help:
--help or --h
show the manual:
eg:man date
open text editor:
nano text.txt
check who login: who
check who login: w
net state: netstat -a
the program runs: ps -aux
change to be root identity:su - 
change to another identity:eg: su - nodemanager
Create a sudo user in CentOS
account information:/etc/passwd
password information:/etc/shadow
group information:/etc/group
File Permission:
https://tutonics.com/2012/12/linux-file-permissions-chmod-umask.html

d is for folder, is for file, | is for link file, b is for equipment, c is for I/O equipment.

r:4, w:2,x:1

for folders, who only has read permission if there is no x(execute), like r– cannot access the folder.x let you can access the folder, like when using cd xxx command.

for files, w permission enable you change the content, but cannot delete the file.

change the system language:

/etc/locale.conf

change the group the files belonged to, the group must in /etc/group: chgrp

eg: chgrp groupname xxx.txt

change the owner of the files, the owner must in /etc/passwd: chown -R will influence the sub folders and files

eg: chown -R ownername xxx.txt

change owner and group:

eg: chown ownername:gourpname xxx.txt

copy a file: cp

-i if there is the same one exists, system will ask your confirmation

cp -i sourcefile destination

-a make it totally the same including the permission information

-s make a shortcut

-u update the destination with newer file.

-d copy shortcut to shortcut

-l copy shortcut’s content(real one, not itself, can be neglected)

change the permission: chmod

eg: chmod -R 777 xxx.txt

some useful permission, for example:

-rwxr—–: chmod 740 filename

-rwxr-xr-x: chmod 755 filename

chmod u=rwx,go=rx filename

chmod u=rwx,g=rx,o=r filename

add all(u,g,o) writing permission:

chmod a+w filename

cancel all execute permission:

chmod a-x filename

create a new file:

touch xxx

delete file(-r includes every son):

rm -r xxx

read and show in command line(-n show line number):

eg: cat -n ~/.bashrc

show from tail to start:

eg: tac ~/.bashrc

show with line number:

nl -b a -n rz 1.txt

delete an empty folder(-p includes every parent empty folder):

rmdir -p xx/xx

go to home folder:

cd = cd~

back to the folder just now:

cd -

print environment path variable to screen:

echo $PATH

add a folder to PATH:

PATH="${PATH}:/root"

get basename:

basename /etc/sysconfig/network

get dirname:

dirname /etc/sysconfig/network

print content to search:

more 1.txt

less 1.txt

use /key word and ?keyword to search after and before, n to repeat the action, pageup and pagedown to turn pages, G go to the last line, g go to the first line, q quit less.

revert less:

tac xxx.csv | less

show head 100 line:

head -n 100 1.txt

excludes the last 100 line:

head -n -100 1.txt

show tail 100 line:

tail -n 100 1.txt

excludes the first 100 line:

tail -n +100 1.txt

show if there is new data input:

tail -f 1.txt

show 11 line to 20 line:

head -n 20 1.txt | tail -n 10

meanwhile show the correct line number:

cat -n 1.txt | head -n 20 | tail -n 10

show the different character code result:

eg: od -t oCc 1.txt

eg: echo testword | od -t oCc

show the mtime(content modifying time) of the files:

ll

show the atime(access time) of the files:

ll --time=atime

show the ctime(change time, state of files, cannot be changed) of the files:

ll --time=ctime

create a new file with a certain mtime:

touch -t 202107041412 xxx.txt

default permission setting:

umask

umask -S

umask means needs to deduct from the max permission:

eg: for folders: 777(drwxrwxrwx) – umask number

for files: 666(-rw-rw-rw-) – umask number

change umask default number:

umask 002

show the hide attributes(-a, -d, -R):

lsattr xxx

change the hide attributes(+a, +i, -a, -i):

chattr +a xxx

SUID(4, u+s): special permission on execution file to make the executioner having owner permission in run-time.

-rwsr-xr-x

if s is S, that means as there is no x, it is meaningless

SGID (2, g+s) : special permission on file/folder to make the executioner having group permission in run-time.

SBIT (1, o+t) : special permission on folder to make only the root and owner can delete the sub folders or files.

to add suid, sgid, sbit, the method like below:

chmod 4755 filename

chmod g+s, o+t filename

get detailed information of file:

file xxx.rpm

search a command file(-a means not the first result, show all):

which -a command

check command installed or not:

eg: command -v sshfs

search a file(-l: list the folder will be checked, -b: only check binary file, -m: only check the file in manual path, -s: only check source file, -u: look for others file):

whereis -l filename

locate/updatedb:

-i(Case insensitive): locate -i partfilename

-c(output only the found number): locate -c partfilename

-l(output line number): locate -l 5 partfilename

-S(output db related information): locate -S partfilename

-r(show regex format): locate -r partfilename

updatedb can get the newest result.

find -mtime n:

find files >= 5days ago: find /var -mtime +4

find files <= 4days ago: find /var -mtime -4

find files 4-5days ago: find /var -mtime 4

-user, -group, -nouser, -nogroup

find the files under a folder which is belonged to a user: eg:

eg: find /home -user username

find a file having keyword:

eg: sudo find / -name "*xxx*"

eg: find / -name *.txt

find the number of a certain type:

find ./*.JPG -type f | wc -l

find a certain type file(s: socket, b,c: equipment, f:file, d: folder, l:link, p: FIFO):

eg: find /run -type s

eg: +, \; means finish

find ./ -type f -name mem* -exec cat {} +

find ./ -type f -name mem* -exec cat {} \;

find file with special permission:

eg: find / -perm /7000

find file size over 1M:

eg: find ./ -size +1M

eg: add -exec ls -l {} \; at last if continue to do some action

physical disk file: /dev/sd[a-p][1-128]

eg: /dev/sda1

virtual disk file: /dev/vd[a-d][1-128]

ext2 is indexed allocation

check the disk volume where a certain folder in(-i: show inode):

eg: df -hT ./

except tmpfs Filesystem, e.g: df -hT -x tmpfs

eg: xfs_quota -x -c "df -h" /home

/dev/shm/ is the folder using memory, usually volume is half of the memory

check the folder size:

eg: du -Sah ./

check all the 1st subfolders and files size(c is for summary):

sudo du -hsc ./*

list sorted results of the big 30:

sudo du -ahx ./ | sort -rh | head -n 30

check the folder size with n depth:

sudo du -h --max-depth n ./

similar to hard copy(-f: force): ln fileName shortcutName

similar to soft copy, making link (-f: force) : ln -s fileName shortcutName

check the disk partition state:

lsblk -fp

check partition table type:

parted /dev/sda print

MBR uses fdisk, GPT uses gdisk

eg: gdisk /dev/sda

display partitions: sudo fdisk -l

refresh partition without reboot: partprobe -s

formatting:

sudo mkfs.ext4 /dev/sda

https://phoenixnap.com/kb/linux-format-disk

mkfs.xfs /dev/sda4

mkfs -t xfs -f /dev/sda4

can be used by Linux and windows: sudo mkfs.exfat -n "label" /dev/sdb1

to install mkfs.exfat:

sudo apt-get install exfatprogs

formatting to FAT32: sudo mkfs.vfat -v -I -F 32 /dev/sdb4

can be used by Linux and windows(single file max 4GB):

sudo mkfs.vfat -I /dev/sda

change the label of FAT32 disk: fatlabel /dev/sdb4 UDISK

change the label: sudo e2label /dev/sda labelName

https://stackoverflow.com/questions/16956810/how-do-i-find-all-files-containing-specific-text-on-linux

check the cpu core number:

grep 'processor' /proc/cpuinfo

check xfs file system(should in unmounted state, when the system is in trouble): xfs_repair -n /dev/sda4

mount a partition:

eg: mount UUID="5748de1d-9e6c-420d-ba04-6253d083e414" ./emptyFolderName

mount with a special permission information: eg:

sudo mount -t exfat -o umask=0022,gid=groupID,uid=userID /dev/sda1 /home/user/somewhere

see: Mount device with specific user rights

mount with a certain language code:

eg: mount -o codepage=950,iocharset=utf8 UUID="35BC-6D6B" /data/usb

when the root is read-only, you need to do remount:

mount -o remount,rw,auto /

mount -n -o remount,rw /

mount a certain folder to another:

https://linuxconfig.org/howto-mount-usb-drive-in-linux

eg: sudo mount --bind /home/userName/mountTest /home/userName/SImA/SImA-1.1.10/migration

unmount a device(-f: force):

eg: umount /run/media/user/U

change the xfs disk’s label(-l is to show, -u is to show UUID, -U is to use UUID):

eg: xfs_admin -L labelname /dev/sdb4

generate a new UUID: uuidgen

to change uuid and label for ext4, use tune2fs, eg: tune2fs -L labelname /dev/sdb4

to mount automatically, change the content in:

/etc/fstab

to mount dvd.iso files:

eg: mount -o loop /tmp/xxx.iso /data/xxx

to mount a big file: eg: mount -o loop UUID=”xxx /mnt

check free memory in detail: free -h

total memory: grep MemTotal /proc/meminfo

check swap equipment in detail: swapon -s

grep SwapTotal /proc/meminfo

.zip file unzip:

unzip -P password xxx.zip -d ./targetFolder/

check the content in zip file:

unzip -l xxx.zip

zip a file(-v show the detail information, -d unzip, -1: quick but lower compressed, -9: slow but well compressed, default is 6, -c: show to screen and can be redirected):

eg: gzip -v textfile

eg: gzip -d testfile.gz

eg: gzip -9 -c xxx > xxx.gz

unzip img.gz:

gunzip xxx.img.gz

show the zip file’s content:

eg: zcat xxx.gz

find the content in zipped file:

eg: zgrep -n ‘anycontent xxx.gz

bzip2(-k is to remain the original one) is more compressed than gzip, command is almost the same.

eg: bzip2 filename

show the zip file’s content:

eg: bzcat filename.bz2

xz(-v show detailed information, -k remain the oringal one) is more compressed than bzip2

eg: xz filename

show the zip file’s content:

eg: xzcat filename.xz

unzip tgz file:

eg: tar zxvf xxx.tgz

use tar(-j for bz2, -J for xz, -z for gz, -p keep ther original permission, –exclude= for excluding unwanted one) to make zip folder:

tar -jcv -f filename.tar.bz2 object_folder1 object_folder2

to check what is inside:

tar -jtv -f -filename.tar.bz2

to unzip:

tar -jxv -f filename.tar.bz2 -C destination_folder

to unzip one in the zipped file:

tar -jxv -f filenme.tar.bz2 thatFile

to unzip .tar.gz file: eg:

tar -xvzf shga_sample_750k.tar.gz

to unzip tar.xz file:

tar xf linux-3.12.2.tar.xz

to unzip .tar file, eg:

tar -xvf xxx.tar -C ./

view the contents of tar.gz:

tar -tf filename.tar.gz

back up xfs file system(level 0 means totall backup):

eg: xfsdump -l 0 -L boot_all -M boot_all -f /srv/boot.dump /boot

restore the xfs file system:

eg: xfsrestore -f /srv/boot.dump -L boot_all /tmp/boot

show the difference between two folders:

eg: diff --brief --recursive dir1/ dir2/

eg: diff -r /boot /tmp/boot

make iso file(-r: keep permission information, -V: label, -o: img filename, -m: exclude file or folders, -graft-point: divided separately by rules):

eg: mkisofs -r -V ‘labelname’ -o ./xxx.img -m ./excludefile -graft-point /a=./a /b=./b

check iso information:

eg: isoinfo -d -i ./xx.img

totally copy including the permission:

eg: rsync -a /run/media/a ./c

rsync -avz /backUpFolder userAccount@hostname:/backUpToFolder

refresh and copy the new files to the destination:

eg: rsync -ur --progress --info=progress2 source_folder/ destination_folder/

use like cp -a:

eg: rsync -ah --info=progress2 --info=stats2 source_folder/ destination_folder/

completely make a mirror:

eg: dd if="/etc/passwd" of="/tmp/passwd.back"

cpio can backup equipment file:

to backup, eg: find / | cpio -ocvB > /dev/st0

to restore, eg: cpio -idvc < /dev/st0

change the pure txt file from dos to linux based(-k: keep same mtime information, -n: remain original file):

eg: dos2unix -k -n sourcefilename destinationfilename

change the pure txt file from linux to dos based (-k: keep same mtime information, -n: remain original file) :

eg: unix2dos -k sourcefilename

change txt content from different language code(-f: from code, -t: to code):

eg: iconv -f big5 -t utf8 originalfilename -o newfilename

iconv --list to check all the support codes.

check support shell:

cat /etc/shells

cat /etc/passwd

check command history:

cat ~/.bash_history

show recent n lines history:

history n

Delete specific command No. n:

history -d n

Save changes:

history -w

to add the timestamp in history result, add the content below to .bashrc:

HISTTIMEFORMAT="%Y-%m-%d %T "

then repeat the command line n:

eg: !123

check short command:

alias

set a new short command:

eg: alias lm='ls -al'

cancel alias:

eg: unalias ll

check the command in detail:

eg: type -a ls

bash short key:

The List Of Useful Bash Keyboard Shortcuts

ctrl+u: delete left part

ctrl+k: delete right part

ctrl+a: to the first

ctrl+e: to the end

cancel environment variable: eg: unset xxx

add path environment variable:

eg1: PATH=$PATH:/home/dmtsai/bin

eg2: PATH="$PATH":/home/dmtsai/bin

eg3: PATH=${PATH}:/home/dmtsai/bin

make subprocess use the variable:

export variablename

show all the environment variable:export

generate a random number: (1-100)eg:

declare -i number=$RANDOM*100/32768;echo $number

check current shell’s PID: echo $$

check the error code of last command: echo $?

show cpu and system edition:echo $MACHTYPE

show support locale:locale -a

let the user input the variable content(-p: hint sentence, -t: showing time(s)):

eg: read -p “Please input your name: ” -t 30 name

declare a int variable: eg: declare -i sum=1+2+3

show a variable attribute: eg: declare -p variable

delcare an array: eg: var[1]=”a, var[2]=”b

show the current limit: ulimit -a

history max lines number: $HISTSIZE

show command order: eg: type -a ls

change bash welcome information: /etc/issue

change bash welcome information for remote login: /etc/issue.net

change additional welcome information, only root can: /etc/motd

for login shell: os check config file order: /etc/profile, ~/.bash_profile or ~/.bash_login or ~/.profile, ~/.bashrc

for non-login shell: os check config file: ~/.bashrc

set the config file and let it do some after logout bash: ~/.bash_logout

show the shortcut key: stty

stdout, stderr: eg: find /home -name .bashrc > list_right 2> list_error

stdout and stderr to the same file:

eg: find /home -name .bashrc &> list

eg: find /home -name .bashrc > list 2>&1

throw the content: eg: find /home -name .bashrc 2> /dev/null

stdin from the file: eg: cat > catfile < ~/.bashrc

define the end symbol: eg: cat > file << “eof

if cmd1 pass, then do cmd2: cmd1 && cmd2

if cmd1 fail, then do cmd2: cmd1 || cmd2

to select by command1’s result: command1 && command2 || command3

get a certain command from a line(here 3 is the third one, 5 is the fifth one, c means choose by character):

eg: echo ${PATH} | cut -d :‘ -f 3,5

eg: echo ${PATH} | cut -c 3-5

select keywords content out(-a: check binary file by text, -c: count found words, -i: ignore case, -n: with line number, -v: opposite selection, –color=auto: show with color):

eg: last | grep -v reboot

sort the result(default sort by the first column, -k 2: sort by 2nd column, -n: sort by number, -M: sort by month, -f: ignore case, -b: ignore first space, -r: reversed order, -t: separation symbol, -u: if same just show one):

eg: last | sort -k 2

select out repeated data(-c: count, -i: ignore case):

eg: last | cut -d ‘ ‘ -f 1 | sort | uniq -c

how many lines, words, chracters in the content:

eg: cat /etc/passwd | wc -lwm

save while output(-a: add to the end of the original destination file):

eg: ls -l / | tee -a ~/homefile | more

replace words(-d: delete the words, -s: no repeated words): eg(a -> A): last | tr [a-z] [A-Z]

replace tab by space: eg: cat /etc/man_db.conf | col -x | cat -A | more

replace tab by several spaces(-t: space number): eg: xxx | expand -t 6 filename

join by column: eg: join -1 2 -2 1 1st.txt 2nd.txt

https://shapeshed.com/unix-join/#:~:text=The%20join%20command%20in%20UNIX%20is%20a%20command%20line%20utility,is%20written%20to%20standard%20output.

simple join two file, default by tab(-d: default join symbol is tab): eg: paste file1 file2

split files(-b: unit size, like 1b,1kb,1mb, -l: line number): eg: split -b 300k filename prefixName

recover from split files: eg: cat prefixFile* >> finalFile

use for command can’t use pipe(-0: set for special separation symbol, -e: set for EOF, -p: need confirmation each time, -n: how many parameters each time it needs): eg: find /usr/sbin -perm /7000 | xargs ls -l

check user’s UID/GID information: eg: id root

check content lines in the file(-A: includes lines after, -B: includes lines before):

eg: dmesg | grep -n -A3 -B2 --color=auto 'memory'

check the kernel information: dmesg

select by regular express(3,$d means from 3 until last line delete): eg: nl regular_express.txt | sed '3,$d'

replace by several lines(line 2-5 are replaced by xxx):

eg: nl regular_express.txt | sed '2,5c xxx'

select out several lines(line 2-5 are selected):

eg: nl regular_express.txt | sed -n '2,5p'

insert content into lines(xxx is inserted after line2):

eg: nl regular_express.txt | sed '2a xxx'

insert content into lines(xxx is inserted before line2):

eg: nl regular_express.txt | sed '2i xxx'

to replace some words(-i: sed -i… means directly change on that file and save automatically):

eg: filecontent | sed 's/wordsNeedToBeReplaced/newWords/g'

find all files containing specific text in a folder:

grep -rnw './' -e 'searchPattern'

egrep means grep -E, can use advanced regular express, eg: egrep -v ‘^$|^#’ regular_express.txt

extract content by column(the eg is 1 and 4 col, NF: how many column it has, NR: current row, FS: separation symbol): eg: who | awk '{print $1,$4}'

eg: cat /etc/passwd | awk 'BEGIN {FS=":"} $3<10 {print $1 "\t" $3}'

show column, -F means delimiter, $NF means last column, $1 means first column: eg:

cat /etc/passwd | awk -F ':' '{print $1, $NF}'

compare file by line, usually for ASCII pure text(-b: neglect blank, -B:neglect blank line, -i: ignore case): eg:

diff -bBi file1 file2

compare file by byte, can be used for execution file(-l: show all difference):

cmp -l file1 file2

make patch:

eg: diff -Naur file1 file2 > result.patch

refresh to new file(N means nth folder, if in the same folder N is 0): eg: patch -pN < patchFile

restore to old file: eg: patch -R -pN < patchFile

shell script starts with which bash you want to use: eg: #!/bin/bash

run shell script in this bash: eg: source test.sh

run shell script in son-bash: eg: sh test.sh

test file exist: eg: test -e filename

https://www.computerhope.com/unix/test.htm

check open service ports: netstat -tulnp | grep -n LISTEN

check shell script: eg: sh -n xxx.sh

show shell script before execute: eg: sh -v xxx.sh

show shell script used: eg: sh -x xxx.sh

show current user belonged groups: groups

switch to new group(exit to go back): newgrp groupName

register new account: useradd xxx

change password: passwd userName

show password information: chage -l userName

delete user account(-r: include home): userdel -r username

change shell(-l: show available shell): eg: chsh -s /bin/csh

add group: groupadd groupName

delete group: groupdel groupName

set group password(-A: make user become group administrator): gpasswd groupName

check ACL permission: https://segmentfault.com/a/1190000022541406

getfacl filename

use other user to implement command: eg: sudo -u userName touch xxx

Creating a Sudo-Enabled User

make users and groups having root power automatically:

change /etc/sudoers, use the below:

sudo visudo

add sth like, eg:

root ALL=(ALL) ALL

%wheel ALL=(ALL) ALL

put user into a group: eg: usermod -aG groupName userName

remove user from a group:eg: gpasswd -d userName groupName

check login log: lastlog

restart atd(for one time) service: systemctl restart atd

start while power on: systemctl enable atd

check current state of atd: systemctl status atd

check whether daemon is enabled or not: systemctl is-enabled docker.service

execute scheduled task: at now + 2 minutes, echo “test” > /dev/pts/0, ctrl+d

show current task: atq

delete current task: atrm numberID

check cpu consumption: uptime

check cycled scheduled task: crontab -l

set scheduled task: crontab -e

eg(every 1 minute): */1 * * * * echo "test" > /dev/pts/0

you can change it here: /var/spool/cron/userName

check scheduled task log: cat /var/log/cron

check process state: ps -l

the maxlogins connection is written in: /etc/security/limits.conf

pause a process: ctrl+z

show the background jobs(-r: show only running jobs, -s: show only stopped jobs):

jobs -l

bring background task to foreground: eg: fg %1

start task again in background : eg: bg %1

kill a task directly: eg: kill -9 1

kill a task normally: eg: kill -15 1

reboot a pid process: eg: kill -1 1

kill pid by name:eg: killall -i -9 bash

process persistent in background even after shell dies accidentally: eg: nohup pycharm.sh &

static check the process related to this bash: ps - l

static check all the process: ps aux

dynamic (every 1s)check all the process: top -d 1

process tree: pstree -Aup

check process’s pid: ps aux | grep 'processName' | grep -v 'grep' | awk '{print $2}'

check if the process has restarted: tail -5 /var/log/messages

create a process with a certain nice value:eg: nice -n -5 vim &

change the nice value: eg: renice -5 PIDNumber

check the listening port: netstat -tulnp

dynamic check the hardware information every 1 second(-d: harddisk state): vmstat 1

check what is using the file: eg: fuser -muv /proc

check what is using the file then kill it: eg: fuser -mki /home

find user is using which file: eg: lsof -u username -a

find folder is used by which process: eg: lsof +d /dev

check pid number of process name: eg: pidof systemd rsyslogd

check the SELinux permission of this folder: ls -Z

check process SELinux information: ps -eZ

current SELinux state: getenforce

SELinux policy(/etc/selinux/config): sestatus -vb

getsebool -a

change selinux permission: eg: setsebool -P httpd_enable_homedirs 1

recover default SELinux permission: eg: restorecon -Rv /etc/cron.d

check default SELinux permission setting(-a: add context, -m: mend context, -d: delete context): semanage fcontext -l

check how the port is managed by selinux:

eg: sudo semanage port -l | grep 22

add a port open in selinux:

sudo semanage port -a -t ssh_port_t -p tcp yourPortNumber

delete a port open in selinux:

sudo semanage port -d -t ssh_port_t -p tcp yourPortNumber

check installated software: eg: rpm -qa | grep setroubleshoot

start service:

eg: systemctl start atd.service

stop service:

eg: systemctl stop atd.service

restart service:

eg: systemctl restart atd.service

refresh service config without restart:

eg: systemctl reload atd.service

start service automatically while start os:

eg: systemctl enable atd.service

enable service and start meanwhile:

eg: systemctl enable --now docker

disable automatical start while start os:

eg: systemctl disable atd.service

check the state of the service:

eg: systemctl status atd.service

force to disable the service:

eg: systemctl mask cups.service

recover the forced disabled service:

eg: systemctl unmask cups.service

check all the service on the os:

systemctl list-units --all

systemctl list-unit-files -all

systemctl list-unit-files --type=service

check which mode you are using:

systemctl get-default

change mode to graphic when start os:

sudo systemctl set-default graphical.target

change mode to pure command when start os:

sudo systemctl set-default multi-user.target

swap the mode without reboot os:

sudo systemctl isolate graphical.target

sudo systemctl isolate multi-user.target

check the dependencies between services:

sudo systemctl list-dependencies

check the socket service:

systemctl list-sockets

check service with its port:

cat /etc/services

log for crontab in: /var/log/cron

log for import information or error: /var/log/messages

check the living log saved in memory:

journalctl -f

check the daemon log: eg:

journalctl -u sshd

journalctl -u docker.service --since "2022-10-05 10:10:00"

check the loaded kernel module: lsmod

check a certain kernel module information:eg: modinfo drm

load kernel module(-c: list, -r: remove): eg: modprobe vfat

show network card information: nmcli connection show

check hostname information: hostnamectl

eg: hostname -f

change hostname: eg: hostnamectl set-hostname test.local

show time information in detail: timedatectl

change timezone: eg: sudo timedatectl set-timezone "Asia/Tokyo"

change the time: eg: timedatectl set-time "2021-08-25 17:52"

check the system locale: localectl

check the bash locale: locale

change the system locale:eg: localectl set-locale LANG=en_US.utf8

check the detailed hardware information: dmidecode -t 1

check usb state: lsusb -t

sudo lsusb -v -s busNumber:deviceNumber

refresh hardware instruction file: update-pciids

check the cpu and hard disk usage information: iostat -mt

mail is saved in: /var/spool/mail/

install gcc: yum groupinstall "Development Tools"

show information of groupinstall of sth: eg: yum groupinfo "Development Tools"

remove groupinstalled sth: eg: yum groupremove "Development Tools"

compile c file:

eg:gcc -O -c hello.c, then gcc -o hello hello.o

if used library: eg: gcc sin.c -lm -L/lib -L/lib64 -I/usr/include

check the related lib: eg: ldd -v /lib64/libc.so.6

to verify the file: eg: md5sum google-chrome-stable_current_x86_64.rpm

install by rpm: eg: rpm -ivh xxx.rpm

test possible to install for rpm: eg: rpm -ivh xxx.rpm --test

upgrade existed packages: eg: rpm -Fvh xxx.rpm

check already installed packages: rpm -qa

check the package information in detail: rpm -qi

check the pakcage installed directory information:rpm -ql

check the file is belonged to which package: eg: rpm -qf /bin/sh

verify installed package : eg: rpm -V logrotate

delete package: eg: rpm -e pam

refresh rpm database: rpm --rebuilddb

check software information: eg: yum info mdadm

check the software which can be updated: yum list updates

check a certain software state: eg: yum list chrome*

install a software: eg: yum install pam-devel

update a certain software: eg: yum update pam-devel

delete a certain software: eg: yum remove pam-devel

check firewall setting: firewall-cmd --list-all

open firewall: eg: firewall-cmd --add-service="http"

open firewall permanently: eg:

sudo firewall-cmd --permanent --add-service="http"

sudo firewall-cmd --permanent --add-port=portNumber/tcp

How to remove a port in firewall

How to check if a port is in use on Linux:

https://www.cyberciti.biz/faq/how-do-i-check-if-a-port-is-in-use-on-linux/

eg: sudo netstat -tulpn | grep LISTEN

sudo netstat -tulpn | grep :443

ss -tulpn

How to create a sudo user on centos:

https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-centos-quickstart

show current tty: tty

show current logged in users: w

show the mail stream on console:

eg: tail -f /var/spool/mail/username

How to share folder between host and vmware:

https://alexandrerosseto.medium.com/vmware-linux-how-to-share-folder-between-host-and-vm-62e63419ecbb

sudo vmhgfs-fuse .host:/sharedFolderName /mnt/hgfs/sharedFolderName -o allow_other -o uid=1000

check software installed on debian: apt list --installed

temporarily install in english environment: eg: LANG=en_US ./runInstaller

How to Set Up SSH Keys on Debian 10:

How to Fix Connection Refused by Port 22 Debian/Ubuntu

https://linuxize.com/post/how-to-set-up-ssh-keys-on-debian-10/

check the ssh log: journalctl -u sshd

check the failed login log: lastb -adF

check the login log: last

How to install and enable SSH server on SUSE:

https://www.simplified.guide/suse/enable-ssh

check the registered repos:

yum repolist all -v

repos saving directory: /etc/yum.repos.d

check running GUI environment:

echo $XDG_CURRENT_DESKTOP

curl set with proxy:

curlコマンドにてproxy設定

how to use pscp to copy file from host to guest:

https://superuser.com/questions/532919/how-to-use-pscp-to-copy-file-from-unix-machine-to-windows-machine-where-target-p

pscp.exe -pw MyPassword root@127.0.0.1:/etc/myfolder/myfile.opt "C:\download files"

you can put with putty session in a same folder and use:

pscp.exe -C -load “puttySessionName” “D:\xxx.zipaccountName@hostname:/home/accountName/xxx/

use wget to download from a list written in a file:

wget -i xxxx.txt

use wget to download with breakpoint continue(-c), rename the file(-O), assign the path(-P):

wget -c --no-check-certificate -O xxx.iso -P /home/xxx/Downloads/ https://xxxx.iso

How to configure wget for a proxy:

How to use wget behind a proxy

How to configure yum for a proxy:

yumのproxy設定(centOS 7)

set the signal which will affect the process:

eg: trap “killall background EXIT

https://stackoverflow.com/questions/360201/how-do-i-kill-background-processes-jobs-when-my-shell-script-exits

https://www.cnblogs.com/liuhedong/p/10663842.html

open the bluetoothctl shell:

https://linuxcommandlibrary.com/man/bluetoothctl#tldr0

bluetoothctl

add the content at the last line of a file: eg:

echo 'just a test!' >> ./test.txt

truncate file, empty the file content: eg:

sudo find /var/log -type f -name *.log -exec truncate -s 0 {} +

show block information and UUID: blkid

change the content in a file(-i to save, / or . is delimiter): eg:

sed -i 's/changeFromWord/changeToWord/' targetFileName.txt

echo "test" | sed 's/te/fir/'

sed 's./etc..' paths.txt

run sudo inside a script without password:

echo "sudoerPassword" | sudo -S yourCommand

How to Install xrdp on Ubuntu

force install by .deb file:

dpkg -i --force-depends xxx.deb

limit number of ssh login

check public IP address: curl ifconfig.me -s

How to install and enable EPEL repository on a CentOS/RHEL 7

How To Enable Remote Desktop Protocol Using xrdp on Ubuntu 22.04

securely delete files, directories, and block devices by overwriting their contents with random data(overwriting its contents 3 times with random data. The -v option will display progress information, and the -z option will perform a final overwrite with zeroes to hide the fact that the device was shredded.): eg:

sudo shred -n 3 -v -z /dev/sdb

back up image file: eg:

sudo dd if=/dev/mmcblk0 of=xxx.img bs=4M;sync

sudo dd if=/dev/mmcblk0 | gzip > xxx.img.gz

restore the image file to hard disk: eg:

sudo dd if=xxx.img of=/dev/mmcblk0 bs=4M;sync

gzip -dc xxx.img.gz | sudo dd of=/dev/mmcblk0 status=progress

show boot-up performance:

systemd-analyze blame
Make Ubuntu Not Go in Suspend When Laptop Lid is Closed
/etc/postfix/main.cf: No such file or directory
There are stopped jobs (on bash exit)
make a portal door:
eg: sudo sshfs -o IdentityFile=/home/ubuntu/.ssh/xxx.pem ubuntu@ipAddress:/home/ubuntu/remoteFolder localFoder/
unmount the portal door: 
eg: sudo fusermount -u ./localFoder
centos7 install special python version 
set sudoer account without password:
sudo vi /etc/sudoers
# like below:
%sudo  ALL=(ALL) NOPASSWD: ALL 

scan the change every 3 seconds and show the result:

eg: watch -d -n 3 'free -h'

check environment variables: env

kill the login session: sudo pkill -u userName

sudo pkill -t pts/0

port used by software name:

sudo lsof -i -P -n | grep LISTEN

tmux on Linux(CentOS7)

check entire tmux output log: tmux capture-pane -pS - | less

to test connection: eg: nc -v yourIP yourPort

check ufw status:

sudo ufw status numbered

enable ufw:

sudo ufw enable

reload firewall:

sudo ufw reload

delete rule in ufw:

sudo ufw delete IDNumber

add open port in ufw:

sudo ufw allow portNumber

sudo ufw allow portStart:portEnd/udp

sudo ufw allow portStart:portEnd/tcp

sudo ufw allow from 192.168.2.0/24 to any port portStart:portEnd proto tcp

sudo ufw allow from 192.168.2.0/24 to any port portStart:portEnd proto udp

to limit:

sudo ufw limit from 172.16.7.133 to any port 80 proto tcp

alow a certain IP address:

sudo ufw allow from 192.168.2.0/24 to any port portNumber

make a screen and export the log:

screen -L -S your_session_name

“crtl+a”, and “d” to detach the screen.

check the existing screen:

screen -ls

recover to the screen:

screen -r your_session_ID_or_name

if you copy and use the certs in other windows PC:

use powershell:

icacls.exe certName /reset
icacls.exe certName /grant:r "$($env:username):(r)"
icacls.exe certName /inheritance:r

How to do the CHMOD 400 Equivalent Command on Windows:

solve the dns issue:

sudo systemctl restart dhcpcd

show the MAC address:

ip link show

print header and last several lines:

(head -n 1 xxx.csv && tail -n 10 xxx.csv)

print header and last several lines with certain columns:

(head -n 1 xxx.csv | awk -F, -v OFS=',' '{print $3, $51}' && tail -n 10 xxx.csv | awk -F, -v OFS=',' '{print $3, $51}')


p7zip:

7z a -p[your-password] -mhe=on [archive-name].7z [files-to-archive]

7z a -tzip -p[your-password] [archive-name].zip [files-to-archive]

to unzip:

7z x -p[your-password] [archive-name].zip

7z x -p[your-password] [archive-name].rar

7z x -p[your-password] [archive-name].7z

ark -b -a [archive-name].rar

show the supported hostkeyalgorithm:

ssh -Q sig | tr '\n' ',' | sed 's/,$/\n/'

to enable the supported algorithm:

edit /etc/ssh/sshd_config, add PubkeyAcceptedAlgorithms +ssh-rsa at the bottom, then restart sshd: sudo systemctl restart ssh

edit /etc/ssh/sshd_config, add DenyUsers ubuntu at the bottom, then restart sshd to prohibit a certain user from login

show until to the 2nd folder:

tree -L 2 folder/

disable representation of a certain user in login:

sudo vi /var/lib/AccountsService/users/[userName]

then change SystemAccount to be true.

SystemAccount=true

create key and cert for https:

openssl genrsa -out serverName.key 4096
openssl req -x509 -new -key serverName.key -out serverName.pem -days 365

get free certs from Let’s Encrypt:

sudo apt-get install certbot
sudo certbot certonly --standalone -d [yourDomain]

use ImageMagick to make electronic signature:
convert input.jpg -fuzz 55% -transparent white output.png

transfer jpg to pdf:

convert image1.jpg image2.jpg image3.jpg output.pdf

clear the password in pdf:

qpdf --password=[YOUR_PASSWORD] --decrypt input.pdf output.pdf

list all tmux sessions:

tmux ls

kill the specific tmux session by name or ID:

tmux kill-session -t session-name

To split the PDF into individual pages:

pdfseparate x.pdf x_%d.pdf

test API speed:

curl -o /dev/null -s -w "%{time_starttransfer}\n" [API URL]

check the strength of wifi signal:

iwconfig | grep Signal

connect wifi by command:

sudo systemctl enable --now NetworkManager

# List all available Wi-Fi networks in the area.
nmcli dev wifi list

# Connect to a specified Wi-Fi network using its SSID and password.
nmcli dev wifi connect <SSID> password <password>

# Display a list of all active network connections, showing their status and other details.
nmcli con show

# Disconnect the specified network interface from its network. 
nmcli dev disconnect iface <interface_name>

Monitor partition disk activity:

How to Monitor Disk I/O performance in Linux

iostat -m -p nvme0n1

Check disk activity:

sudo iotop

Monitor network traffic:

sudo nethogs yourNetInterFaceName

Displays the current IP-to-MAC address mappings in the ARP cache for local network communication:

arp -a

display detailed information about file:

stat /path/to/file

download files in the FTP server:

wget -r --ftp-user=yourID --ftp-password='yourPassword' ftp://yourdomain.com:80 ./

hold and unhold apt upgrade for certain software (eg: vsc):

sudo apt-mark hold "code/stable"
sudo apt-mark unhold "code/stable"

check hold state:

apt-mark showhold

list top 10 memory-consuming processes:

ps -e -o pid,ppid,comm,%mem,rss,%cpu --sort=-%mem | head -10
ps -e -o pid,ppid,comm,rss,%cpu --sort=-rss | head -n 10 | awk 'BEGIN {printf "%-8s %-8s %-15s %-12s %-8s\n", "PID", "PPID", "COMMAND", "MEMORY", "CPU%"}
     NR>1 {printf "%-8d %-8d %-15s %-10.2fGB %-8.1f\n", $1, $2, $3, $4/1024/1024, $5}'

conduct a real-time test of the USB camera:

ffplay /dev/video0

This stores crash data files:

/var/lib/apport/coredump

Check which process is using port:
lsof -i:portNumber

Kill the process occupying port in one command:
fuser -k portNumber/tcp

offline install python packages

paste the whl files folder named python to the path C:\temp(in req.txt named the main modules you want to install), and go to the python.exe directory which you want to install on:

python -m pip install -r "C:\temp\python\req.txt" --no-index --find-links file://"C:\temp\python"

or to the path and:

for %x in (*.whl) do python -m pip install %x

by the way, using proxy(2 dashes before proxy):

pip install modulename --proxy http://user:password@proxyserver:port

Mysql Commands

to login: mysql -u username -p

check mysql database stored in : select @@datadir;

show all the databases: show databases;

use a certain database: use DBNAME;

show all the tables: show tables;

show the create time of a certain table in a certain database:

SELECT create_time FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'databasename' AND table_name = 'tablename';

show the last modified time:

SELECT update_time FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'databasename' AND table_name = 'tablename';

give the privilege of a certain user:

GRANT ALL ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password';

to check the max connection times per hour:

https://fromdual.com/max-used-connections-per-user-account

SELECT User, Host, max_connections, max_user_connections
FROM mysql.user;

show the grants for current user: SHOW GRANTS FOR CURRENT_USER;

create database:

create database databasename;

drop database:

DROP DATABASE databasename;

Create a new user:

CREATE USER userName IDENTIFIED BY 'newpassword';

knowledge in Spotfire

jar driver is in the folder below:

tibco\tss\7.9.0\tomcat\lib

or

tibco\tss\7.9.0\tomcat\webapps\spotfire\WEB-INF\lib

the upgrade tool UIconfig which locates in tibco\tss\10.10.0\tools\upgrade, may sometimes need:

Vc_redist.x64.exe and Vc_redist.x86.exe

XML View tab in configuration tool shows all the configuration, and open it by the path:

tibco\tss\7.9.0\tomcat\spotfire-bin\uiconfig.bat

after upgrading, the data functions need to be trusted, use the command below(if memory is not enough, using single thread, befor auto and single, it’s 2 -):

tibco\tss\10.3.10\tomcat\spotfire-bin>config find-analysis-scripts --auto-trust-data-functions=true --single-threaded

you can check the trust and untrust scripts, report in tibco\tss\10.3.10\tomcat\spotfire-bin\find-analysis-scripts>

to keep the weplayer’s language same with the visitor’s language:

tibco\tss\10.3.10\tomcat\webapps\spotfire\WEB-INF>
copy ResourcesHeader.properties and ResourcesWeb.properties, and then rename it and add ‘_en_US‘ at last

need to configure the configuration tab->join database in configuration tool after configuring the upgrade tool

ChemDraw-JS-Setup-18.1.1.exe for only 1, JS includes the ChemDraw ActiveX
ChemDraw ActiveX Enterprise Constant.zip for 2 more, and it is a must for the webplayer server. Must reinstall the CDAX manually if it is also used as a webplayer server meanwhile.

spotfire_webclipboard_setup.exe needs to transfer the installed content to the right folder like tibco\tss\10.3.10\tomcat\webapps\ROOT\webclipboard, you need to check the version in the path is correct or not

to open the anonymous authentication:

  1. configuration tool->configuration->anonymous authentication->Yes
  2. by command prompt, in path: \tibco\tss\10.3.10\tomcat\spotfire-bin>config enable-user --username=ANONYMOUS\guest
  3. let anonymous user (a subgroup)in a certain group having spotfire consumer licences
  4. making a folder in library, let anonymous user access possible

to deal with the problem that two different version installed in same server, the node manager may use the old one(basically step 3 and 4 is enough):

tip: the first node ID information line is for nodemanager, the second node ID line is for spotfire server.

  1. check the antivirus block list
  2. check the spotfire_db.nodes in database and found the old version’s ID number.
  3. to check the nodes ID, by command prompt: \tibco\tss\10.3.10\tomcat\spotfire-bin>config list-nodes
  4. by command prompt: \tibco\tss\10.3.10\tomcat\spotfire-bin>config delete-node --id=xxxxxxx
  5. change the content in \tibco\tsnm\10.3.10\nm\config\nodemanager.properties, and restart node manager

to link well with chemical db which is to save chemical structure, we must change the configuration by the commands below in command prompt(space below –value):

tibco\tss\10.3.10\tomcat\spotfire-bin>

1.config.bat export-config --force
2.config set-config-prop --name=information-services.parameter-expression-validation --value=false
3.config import-config -c "disable iim validation"

config commands:

https://docs.tibco.com/pub/spotfire_server/7.13.0/doc/html/TIB_sfire_server_tsas_admin_help/GUID-2F0618ED-0B02-4065-9364-F76C2A8F0C9C.html

Windows service account should set to be an AD controlled account for node manager(webplayer), so that the webplayer can get the information from not only the local but also its neighbours’

eg: domain name/web player ad account

to set the default saving path when save file in the library:

UI config -> Configuration Tab->Public Address:

Enable custom public address:Yes

Public address URL: spotfire server full name

when under active directory, to give the node manager ability to visit other server’s file

windows server 2012
->
server manager-> computer administration->system tool->
local user and group-> group-> Administrators
->double click->add the ad account to local

spotfire use the map source in: https://geoanalytics.tibco.com/

export (command: tibco/tss/10.3.10/tomcat/spotfirebin->config export-service-config –capability=WEB_PLAYER –deployment-area=XXX) and set the Spotfire.Dxp.Worker.Host.exe.config file in path:\tibco\tss\10.3.10\tomcat\spotfire-bin\config_Web Player\root, and import it, insert the userid and password, eg:

<!-- Proxy authentication settings. -->
<!-- To use these, you need to add a proxy section, including the proxy address,  to section "system.net/defaultProxy/" below. -->
<setting name="ProxyUsername" serializeAs="String">
<value>USERID</value>
</setting>
<setting name="ProxyPassword" serializeAs="String">
<value>PASSWORD</value>
</setting>
<!--Authentication settings for TIBCO Spotfire Statistics Services -->
<!-- A list of URLs -->

also add in:

<system.net>
<defaultProxy enabled="true">
<bypasslist></bypasslist>
<proxy scriptLocation="http://XXXXXXXXXX.pac"/ >
</defaultProxy>
</system.net>

and remeber to use it in webplayer

copy the matplotlib additional files tcl8.6, tk8.6 to the spotfire’s/nodemanager’s inside python/Lib folder if you want to use the text area to plot

settings when using active domain controller:

1.use administrator account to login the win server

2.lsnrctl stop the listner, and stop the service

3.set the oracle’s service using administrator to log on

eg: OrcaleServiceORCL, OracleOraDB19Home1TNSListener, OracleVssWriterORCL

4.then change the listener.ora and tnsnames.ora in the path below C:\app\oracle\product\19.3.0\dbhome_1\network\admin

for listener.ora:

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = testserver2016.test.local)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

for tnsnames.ora:http://blog.sina.com.cn/s/blog_7c0e26230100t0ci.html

ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = testserver2016.test.local)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)

5. then restart the service above(OrcaleServiceORCL, OracleOraDB19Home1TNSListener, OracleVssWriterORCL)

6.change:

set CONNECTIDENTIFIER=//testserver2016.test.local/ORCL

in the sql script

7.then go on the normal installment

need to set the spotfire server address into trust sites of IE after installing Analyst immediately on server:

https://community.tibco.com/questions/error-occurred-while-logging

LDAP configuration in Spotfire:

https://docs.tibco.com/pub/spotfire_server/10.10.2/doc/html/TIB_sfire_server_tsas_admin_help/server/topics/configuring_ldap.html

in addition:

  1. tick Authentication and User directory, choose Microsoft Active Directory
  2. LDAP username: eg: Test\Administrator
  3. LDAP server URL: eg: ldap://testserver2016.test.local:389
  4. Context names: here, the OU means the accounts you want to use belonged to, eg: OU=XXX,DC=test,DC=local

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ldap/distinguished-names#:~:text=The%20LDAP%20API%20references%20an,a%20UTF%2D8%20string%20format

use LDAP Browser to find a certain OU(build it and search a certain account name to find its upper OU): https://www.ldapadministrator.com/resources/english/help/la20121/ch08s01.html

to list and get the node manager service infromation:

go to cmd:

C:\tibco\tss\10.3.9\tomcat\spotfire-bin>config list-service-configs

to delete the node manager service:

C:\tibco\tss\10.3.9\tomcat\spotfire-bin>config delete-service-config --config-name=servicename

in default communication configuration between AP server and nodemanager server, the port 9443 is for https implement communication, and 9080 is the base layer for http

if using oracle pdb‘s instance:

in batch file:

the instance name should be: //localhost/orclpdb

and when import the dump file, you need to put it into the random folder it made, like app/oracle/admin/orcl/dpdump/F2BBAEADB6274F34AFBAEC1772546E79

for JA16SJISTILDE, need to having the driver of orai18n.jar

The module for installation is in the path, such as the Visual C++ installer:

C:\Program Files(x86)\TIBCO\Spotfire\10.3.3\Modules\Lead Discovery_8.3.0.410\VCRedist

Default Firewall Settings:

in spotfire server:

open for human users: 80

open for nodemanager(backend):9080(for http), 9443(for https)

in nodemanager server:

open for spotfire server: 9081,9444

open for webplayer: 9501

* open for chemdraw: 81

Cannot open information link bug will happen if in UIconfig, data source template has the same name:

eg:《jdbc-type-setting》《type-name》XXX《/type-name》, XXX should not be the same.

method to change content in uiconfig by command:

1. output the saved state:

uiconfig->Export configuration from database->Load configuration from files

2. edit the xml files and import it.

eg: go to spotfire-bin directory, and use command: config import-config config.xml –comment=”disable postgreSQL”

Port 9005 will be used by spotfire, if it cannot be used, the service will stop automatically.

export library by command(default domain is SPOTFIRE):https://docs.tibco.com/pub/spotfire_server/10.10.4/doc/html/TIB_sfire_server_tsas_admin_help/server/topics/export-library-content.html

eg:

config export-library-content --tool-password=pw --file-path=C:/outputfilename --item-type=all_items --user=spotfire@SPOTFIRE --include-access-rights=true --library-path="/Test for case have space"

import library by command eg:

config import-library-content --tool-password=pw --file-path="C:/outputfilename.part0.zip" --item-type=all_items --user=spotfire@SPOTFIRE --conflict-resolution-mode=KEEP_NEW --include-access-rights=true --library-path="/"

change the nodemanager domain information in:

tibco\tsnm\10.3.9\nm\config\nodemanager.properties

change the nodemanager’s instances domain information in:

tibco\tsnm\10.3.9\nm\config\config.json

change domain information for the spotfire server is required change the information in:

app\oracle\product\19.3.0\dbhome_1\network\admin\listener.ora

and

app\oracle\product\19.3.0\dbhome_1\network\admin\tnsnames.ora

and then restart the oracle service: OracleOraDB19Home1TNSListener,OracleServiceORCL

how to check the end users’ using webplayer frequent:

\tibco\tsnm\7.11.7\nm\logs\AuditLog

trust all scripts, template, data functions:

config find-analysis-scripts -t spotfire -s true -d true -q true --single-threaded

to make the spotfire webconsole page in https, you need ssl certificate, the example to make the .jks file is:

C:\tibco\tss\10.10.4\jdk\bin>keytool -genkey -alias servername -keyalg RSA -keypass pw -storepass pw -keystore keystore.jks

then move this jks file to C:\tibco\tss\10.10.4\tomcat\certs

Stop the server service, then edit C:\tibco\tss\10.10.4\tomcat\conf\server.xml, hide the http block, recover the https block, change information like:

    <Certificate certificateKeystoreFile="./certs/keystore.jks"
                 certificateKeystorePassword="pw"
                 certificateKeystoreType="jks"/>

must delete the content below!

truststoreFile=”./certs/testserver2016.jks”
truststorePass=”changeit”
truststoreType=”jks”

at last restart the server service.

change to be DNS:

config switch-domain-name-style –tool-password=pw –new-domain-name-style=dns

How to make Kerberos Authentication:

AD User and Computer:

C:\Users\Administrator>setspn -S HTTP/testserver2016 svctss1010

C:\Users\Administrator>setspn -S HTTP/testserver2016.test.local svctss1010

C:\Users\Administrator>setspn -l svctss1010

check 128 and 256 support

C:\Users\Administrator>ktpass /princ HTTP/testserver2016.test.local@TEST.LOCAL /ptype krb5_nt_principal /crypto ALL /mapuser svctss1010 /out spotfire.keytab -kvno 0 /pass yourpassword

Paste spotfire.keytab to C:\tibco\tss\10.10.4\tomcat\spotfire-config

Edit C:\tibco\tss\10.10.4\tomcat\spotfire-config\krb5.conf as follows:

[libdefaults]
default_realm = TEST.LOCAL
default_keytab_name = spotfire.keytab
default_tkt_enctypes = aes256-cts-hmac-sha1-96 aes128-cts rc4-hmac
default_tgs_enctypes = aes256-cts-hmac-sha1-96 aes128-cts rc4-hmac
forwardable = true

[realms]
TEST.LOCAL = {
kdc = testserver2016.test.local
admin_server = testserver2016.test.local
default_domain = test.local
}

[domain_realm]
.test.local = TEST.LOCAL
test.local = TEST.LOCAL

[appdefaults]
autologin = true
forward = true
forwardable = true
encrypt = true

C:\tibco\tss\10.10.4\jdk\bin>kinit.exe -k -t C:\tibco\tss\10.10.4\tomcat\spotfire-config\spotfire.keytab HTTP/testserver2016.test.local@TEST.LOCAL

Then delete the generated ticket for security reason.

In spotfire UIConfig, change the Authentication be Kerberos.

Then changes Domain Tab, Domain name style to be DNS, Parse user and domain name to be Yes.

C:\tibco\tss\10.10.4\tomcat\spotfire-bin>config switch-domain-name-style –tool-password=UIconfigpassword –new-domain-name-style=dns

Make sure Post Authentication Filter to be Block.

In Authentication:Kerberos Tab,

Service principal name to be:HTTP/testserver2016.test.local@TEST.LOCAL

Choose Keytab file and configuration file, Delegation policy Never, if the nodemanger and spotfire server in the same server.

Then save the change in uiconfig.

In client side, IE properties, add in the server site into local intranet site,

click customized level, at the lase choose only automatically login in intranet,

in detail setting tab, make sure you checked use Windows authentication.

restart the spotfire service, now you should login without input password.

synchronize ldap group information without reboot the server service:

spotfire-bin>config list-users -f

Error when running Information links using On-Demand with more than 1000 values in TIBCO Spotfire version 11.4.0/11.4.1/10.10.5/10.10.6

https://support.tibco.com/s/article/Error-when-running-Information-links-using-On-Demand-with-more-than-1000-values-in-TIBCO-Spotfire-version-11-4-0-11-4-1-10-10-5-10-10-6

Opening multiple TIBCO Spotfire Analyst client sessions on the same machine causes the previous Analyst session to ask for login prompt:

https://support.tibco.com/s/article/Opening-multiple-TIBCO-Spotfire-Analyst-client-sessions-on-the-same-machine-causes-the-previous-Analyst-session-to-ask-for-login-prompt

to refresh the AD information and shown in spotfire(no need to restart the spotfire service):

https://support.tibco.com/s/article/Tibco-KnowledgeArticle-Article-42505

config.bat list-users -f

communicate between Spotfire Server and Node Manager without going through a proxy, you need to refresh the configure file for web player, append the red part, and grey is optional:

 <system.net>

       <defaultProxy enabled="true"> 

        <bypasslist>

            <add address="Service IP, like web Player, Python Service, etc." /> 

        </bypasslist>

        <proxy bypassonlocal="true" proxyaddress="Proxy Server IP" />

       </defaultProxy>

     </system.net>

Configure Authentication Windows NT:

Authentication: BASIC Windows NT

User directory: Windows NT

Add Domains name, eg: test

Wildcard domain: Yes

Sleep time (minutes): 60

Domain name style: NetBIOS(e.g.RESEARCH)

Collapse domains: No

Parse user and domain name: Yes

Default domain: test

Creating the Spotfire SPK for Other Spotfire Analyst users

create the R package spk file for spotfire analyst(multcomp, foreign R package example):

library(SpotfireSPK)
install.packages(c("multcomp","foreign"))
writeLines("Packages: multcomp,foreign", "MySpotfireSPK1.dcf")
buildSPK("MySpotfireSPK1.dcf", "MySpotfireSPK1.spk")
cat(readLines("MySpotfireSPK1.dcf"), sep="\n")

export a certain config of webplayer:

\spotfire-bin>config export-service-config --config-name=webconfig2

export the active server configuration(configuration.xml):

config export-config --tool-passrod=yourPassword

import and activate the server configuration(configuration.xml):

config import-config --tool-password=yourPassword --comment=anyComment

command help, eg: config help import-config

preventing administrators from adding local users when using LDAP:

config set-config-prop --name=user-directory.allow-database-user-creation --value=false

export the config by the name: eg:

\tomcat\spotfire-bin>config export-service-config --config-name=webconfig2

Enabling the SSL connector on Spotfire Server

show login interface: Spotfire.Dxp.exe /forceshowlogindialog

open library version control:

config.bat  export-config --force -t yourPassword
config set-config-prop --name=library.versioning.enabled --value=true
config import-config -c "library-version" -t yourPassword

disable the check of the certs for Mods:

config.bat  export-config --force -t yourPassword
config set-config-prop --name=security.code-trust.validate-uploaded-cert --value=false
config import-config -c "trust-modes" -t yourPassword

search the files by size in library: content_size:>2MB

Microsoft Docs Command and Windows Tricks

check the connection to certain pc, and check its ip address:

ping computer fullname -4

to check the computername in command prompt:

set com

or to see the environment variable path:

set

check current user logined information in the OS:

set user

check all port:
netstat -bn
to check who has occupied the port:
netstat -ano| findstr 8080
to show the pid number:
tasklist | findstr 1048
to kill process:
taskkill /pid 1048 /F

to the directory from root drive: cd \foldername

set service start manually:

sc.exe config

sc config serviceName start=demand

start service net connection:

net start servicename

stop service net connection:

net stop servicename

show the share folders for this computer:

net use

delete the existed link: Net Use 命令用法

net use * /delete

map a network shareto a drive letter

eg: net use h: \\<servername>\<sharename>

view network resources:

eg: net view \\<servername>

eg: net view /workgroup:<workgroupname>

use telnet client to a web server on TCP port as follow:

telnet example.com 80

clean the screen:

cls

show planned tasks:

schtasks

checking the current logon user:

query user

check domain user account:

net user XXX /domain

check domain group:

net group XXX /domain

check the ip address of a certain hostname:

nslookup hostname

by a certain DNS server:

nslookup hostname 8.8.8.8

also to check the server name:

eg: nslookup 8.8.8.8

in nslookup dialog, check the ldap server information:

set types=all
_ldap._tcp.domainName

get cpu information from command prompt:

wmic cpu get caption, deviceid, name, numberofcores, maxclockspeed, status

to remote desktop:

mstsc

using batch file to start and stop service automatically, eg:

net start "a service showing name"

net stop"a service showing name"

use ssh to connect to the EC2 instance:

1.ssh -i "XXX.pem" XXX@.domain -L localport:10.19x.xx.xx:serverport

localport can be any port not been used

2.open the mstsc(remote desktop)

computer: localhost:localport

server IP\Administrator

unzip a msi file in command line:

msiexec /a "xxx.msi" targetdir="D:\target_folder" /qn

to recover the installation successfully when using remote desktop:

IBM Spectrum Protect Client のインストールが Windows Server プラットフォーム上でハングする

if you can access a remoted share folder, use \\servername\C$ to access the C drive

register the machine name for a certain ip address:

C:\Windows\System32\drivers\etc\hosts

eg: 127.0.0.1 localhost

check security ID:

wmic useraccount where name='xxx' get sid

How to uninstall .net:

How to uninstall and remove .NET Framework 4.6, 4.7, or 4.8

.NET Framework versions and dependencies

.NET Framework versions and dependencies

safety error about remote desktop:

Windowsで「要求された関数はサポートされていません」でリモートデスクトップ接続出来ない時の暫定対応

how to install Internet Information Services(IIS):

Windows Server 2016 にインターネット インフォメーション サービス (IIS) をインストールする (IIS – Internet Information Service Tips)

Cannot find IIS Service in Windows 7

check hostname:

hostname

start windows task scheduler:windows 10 如何设定计划任务自动执行 python 脚本

Windows+R->taskschd.msc

How To Install OpenSSL on Windows: How To Install OpenSSL on Windows

Keytool for pfx> JKS:

keytool -importkeystore -srckeystore mypfxfile.pfx -srcstoretype pkcs12 -destkeystore clientcert.jks -deststoretype JKS

OpenSSL for CER & PVK file > P12:
openssl pkcs12 -export -name certificationName -in certificationName.cer -inkey certificationName.key -out certificationName.p12

Keytool for p12 > JKS:
C:\tibco\tss\10.3.9\jdk\bin\keytool -importkeystore -destkeystore certificationName.jks -srckeystore certificationName.p12 -srcstoretype pkcs12 -alias certificationName

use remote desktop from server need to set:

How to Disable Internet Explorer Enhanced Security Configuration in Server 2016

get directory information: tree /f > text.txt

open Local Security Policy: secpol.msc

Display the contents of a Kerberos credentials cache or key table: klist

star menu programs shortcut is in: shell:common programs

delete folder within contents: eg: echo y | Rmdir /S "PyCharm Community Edition 2020.2.1"

rd /S “xxx

https://geniushub.io/how-to-delete-files-folders-directories-cmd-windows-command-line-prompt-del-rmdir/

rename file or folder: eg:

rename old.txt new.txt

rename old new

delete file: eg:

del /f file.txt

del *.*

copy file:eg:

copy "xxx.doc" test_folder

copy "xxx.doc" test.doc

move file:eg:

move "xxx.txt" ../

How to create an infinite loop in Windows batch file:

for /l %%x in (1, 0, 10) do (
   echo %%x
)

How to Solve New Simple Volume Greyed out?

如何删除隐藏的Windows10恢复分区

diskpart
list disk
select disk 0
list partition
select partition 2
delete partition override

to install .Appx: PowerShell cmdlets you can use to install an .Appx package, eg:

Add-AppxPackage -Path "C:\Path\to\File.Appx"

How to install .Appx or .AppxBundle on software Windows10

sleep command:

To pause the command processor for ten seconds then make directory:

timeout /t 10 & mkdir xx

To pause the command processor indefinitely until a key is pressed:

timeout /t -1 && rd t

To pause the command processor for 10 seconds and ignore any keystroke:

timeout /t 10 /nobreak

execute only if the first exited successfully:

dir && echo foo

check the malsoftware:mrt.exe

trace the connect: eg: tracert -d yahoo.co.jp

list local NetBIOS names: nbtstat -n

list remote NetBIOS names, referenced by IP address: nbtstat -A 192.168.1.1

list remote NetBIOS names, reference by name: nbtstat -a server1

check the user account in windows:

wmic useraccount list full

disable account:

How to Enable or Disable a User Account in Windows 10

eg: net user HomeGroupUser$ /active:no

create new user($ means hidden):

net user xxx$ pw /add

check the wifi signal: netsh wlan show interface

check the connection of the interface: netsh interface show interface

check the ip address by interface: netsh interface ip show address | findstr "IP Address"

reset the network: netsh winsock reset

get the wifi report: netsh wlan show wlanreport

check current record in resolver cache: ipconfig /displaydns

clear resolver cache: ipconfig /flushdns

check .NET Frame version:

Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse | Get-ItemProperty -name Version,Release -EA 0 | Where { $_.PSChildName -match '^(?!S)\p{L}'} | Select PSChildName, Version, Release

How can I determine my user account’s OU in a Windows domain?

gpresult /r | find "OU"

open firewall by cmd: control firewall.cpl

restart OS immediately by cmd: shutdown -r -t 0

check port is open from outside of server: Test-NetConnection -Port portNumber -ComputerName ipAddress -InformationLevel Detailed

Windows下的chcp命令

eg: chcp 65001 >nul

go to user folder: %USERPROFILE%

release IP: ipconfig /release "WLAN"

renew IP: ipconfig /renew

get dns cache: ipconfig /displaydns | clip

get MAC information: getmac /v

get energy report: powercfg /energy

get energy sleep report: powercfg /sleepstudy /duration 28

get battery report: powercfg /batteryreport

displays file name extension associations: assoc

modifies file name extension associations: assoc .dts=PotPlayerMini64.DTS

Enable/disable firewall: netsh advfirewall set allprofiles state on/off

show the routing table: route print

restart to BIOS immediately: shutdown /r /fw /f -t 0

check certain group belonged context name OU:

dsquery group -samid groupName

check group members by OU context name:

dsget group "CN=aaa,OU=Dept,OU=Auto,OU=Groups,DC=XX,DC=local" -members

check public IP address: curl -L ip.tool.lu

outlook filter: eg:

from:xxx@xxx.com received:4/1/2022..4/30/2022 hasattachments:true

currently used wallpaper: %AppData%\Microsoft\Windows\Themes\CachedFiles

Windows Spotlight Pictures:

%LocalAppData%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets

How to find your BitLocker recovery key | Microsoft

check the BitLocker state:

manage-bde -status

show the subfolder and included files:

dir "yourPath" /s /b /a-d

Run without Administrator Permission:

Set __COMPAT_LAYER=RunAsInvoker
Start xxx.exe

check the hash value:

CertUtil -hashfile "your File Path" MD5

powershell command to off Windows Defender:

Set-MpPreference -DisableRealtimeMonitoring $true

powershell command to on Windows Defender:

Set-MpPreference -DisableRealtimeMonitoring $false

Altering File Access:

  • Gain Ownership:
    takeown /f xxx.pem
    Grants current user ownership of xxx.pem.
  • Modify Permissions:
    icacls xxx.pem /grant Administrators:F
    Gives Administrators full access to xxx.pem.

Manual Installation of OpenSSH Using PowerShell

  1. Install OpenSSH Server: Open PowerShell as an administrator and run:
    Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
  2. Start SSH Service: Start the service and set it to automatic startup:
    # Get the service named sshd and start it
    Get-Service -Name sshd | Start-Service
    # Get the service named sshd and set its startup type to automatic
    Get-Service -Name sshd | Set-Service -StartupType Automatic

    # Check the status of the service named sshd
    Get-Service -Name sshd
  3. Configure Firewall Rules: Ensure the firewall allows SSH connections:
    New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

Disable the startup item:

Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "Wechat"

display hard disk volumes with their sizes in a human-readable format:

Get-Volume | Select-Object FileSystemLabel, DriveType, DriveLetter, @{Name="Size(GB)"; Expression={[math]::Round($_.Size / 1GB, 2)}}, @{Name="FreeSpace(GB)"; Expression={[math]::Round($_.SizeRemaining / 1GB, 2)}}

display memory information in a human-readable format:

Get-ComputerInfo | Select-Object @{Name="TotalPhysicalMemory (GB)"; Expression={[Math]::Round($_.CsTotalPhysicalMemory/1GB, 2)}}, 
                                 @{Name="PhysicallyInstalledMemory (GB)"; Expression={[Math]::Round($_.CsPhyicallyInstalledMemory/1GB, 2)}}, 
                                 @{Name="TotalVisibleMemorySize (GB)"; Expression={[Math]::Round($_.OsTotalVisibleMemorySize/1MB, 2)}}, 
                                 @{Name="FreePhysicalMemory (GB)"; Expression={[Math]::Round($_.OsFreePhysicalMemory/1MB, 2)}}, 
                                 @{Name="TotalVirtualMemorySize (GB)"; Expression={[Math]::Round($_.OsTotalVirtualMemorySize/1MB, 2)}}, 
                                 @{Name="FreeVirtualMemory (GB)"; Expression={[Math]::Round($_.OsFreeVirtualMemory/1MB, 2)}} | Format-Table -AutoSize

display CPU information in a human-readable format:

Get-WmiObject -Class Win32_Processor | Select-Object Name, DeviceID, NumberOfCores, NumberOfLogicalProcessors, AddressWidth, MaxClockSpeed, L2CacheSize, L3CacheSize | Format-Table -AutoSize

show the files in the current directory:

Get-ChildItem | Format-Table Name, @{Name="Size"; Expression={
    if ($_.Length -gt 1GB) {
        "{0:N2} GB" -f ($_.Length / 1GB)
    } elseif ($_.Length -gt 1MB) {
        "{0:N2} MB" -f ($_.Length / 1MB)
    } elseif ($_.Length -gt 1KB) {
        "{0:N2} KB" -f ($_.Length / 1KB)
    } else {
        "$($_.Length) B"
    }
}}, LastWriteTime -AutoSize

delete a file:

Remove-Item -Path '.\yourFileName'

activate windows 10/11:

slmgr /ipk W269N-WFGWX-YVC9B-4J6C9-T83GX
slmgr /skms kms8.msguides.com
slmgr /ato

display GPU information in a human-readable format:

Get-WmiObject -Namespace "root\cimv2" -Query "SELECT * FROM Win32_VideoController" | Select-Object Name, @{Name="AdapterRAM(GB)";Expression={[Math]::Round($_.AdapterRAM / 1GB, 2)}}, DriverVersion, VideoProcessor

display GPU detailed information:

Get-WmiObject -Namespace "root\cimv2" -Class Win32_VideoController | Select-Object Name, PNPDeviceID, VideoArchitecture, VideoMemoryType, AdapterCompatibility, AdapterDACType, DeviceID, InstalledDisplayDrivers, Monochrome, Status

activitate windows11:

irm https://massgrave.dev/get | iex

pandas 1.0以后pd.concat()里join_axes消失的变化

以前的pandas版本太低,pandas==0.24.2,于是升级到了pandas 1.1.1

版本变化太大,当然有很大变化,其中concat合并数据框的参数join_axes被剔除了,本来是用来指定对齐参照索引的,这功能没了

调查了下,说是让用.reindex()来代替。

concat(外接join=’outer’的话)基本功能就是按照各个数据框的索引(没有指定的话就是默认索引)拼接,没有数据的部分就用nan顶替

试验如下:

cands = pd.DataFrame({'order': [1, 2, 3],
                      'a': [10, 20, 30],
                      'b': [40, 50, 60],
                      'c': [70, 80, 90],
                      'd': [100, 110, 120]})
acq = pd.DataFrame({'order': [6, 2, 1],
                    'A': [4, 5, 6],
                    'B':[7, 8, 9]}) 
geo_mean_acq = pd.DataFrame({'order': [1, 3]})

cands:
  order a    b   c   d
0  1    10   40 70 100
1  2    20   50 80 110
2  3    30   60 90 120 

acq:
  order A B
0  6    4 7
1  2    5 8
2  1    6 9

geo_mean_acq:
   order
0   1
1   3

cands.set_index('order', inplace=True)
acq.set_index('order', inplace=True)
先各自把cands和acq的order这一列当作index,方便实验比较

result1 = pd.concat([cands, acq, geo_mean_acq], join='outer', axis=1)

result1:
   a   b    c     d     A    B  order
0 NaN  NaN  NaN  NaN   NaN  NaN 1.0
1 10.0 40.0 70.0 100.0 6.0 9.0 3.0
2 20.0 50.0 80.0 110.0 5.0 8.0 NaN
3 30.0 60.0 90.0 120.0 NaN NaN NaN
6 NaN  NaN  NaN  NaN   4.0 7.0 NaN

也就是说非index列拼接直接是按照各自的索引号对应横着(axis=1时)拼接,
新的索引的最大值是拼接数据里索引最大值,凡是空缺都用Nan来填补

所以在拼接前一定确保要拼接的数据框们和最终合并输出结果时候的索引是一样的

至于.reindex()
cands.reindex(acq.index)
把cands的索引变成acq的索引,当然索引对应的数值也跟着变,排序也变化
结果是:
       a  b    c   d
order
6     NaN NaN NaN NaN
2     20  50 80 110   
1     10  40 70 100 
注意顺序变化了,是6,2,1

假如是pd.concat([cands, acq], join='outer', axis=1)
结果是:
        a     b     c    d   A    B
order
1       10.0 40.0 70.0 100.0 6.0 9.0
2       20.0 50.0 80.0 110.0 5.0 8.0
3       30.0 60.0 90.0 120.0 NaN NaN
6       NaN  NaN   NaN  NaN  4.0 7.0

假如pd.concat([acq, cands], join='outer', axis=1)
结果是:
        A    B    a    b     c     d
order
1       6.0 9.0 10.0 40.0 70.0 100.0
2       5.0 8.0 20.0 50.0 80.0 110.0
3       NaN NaN 30.0 60.0 90.0 120.0
6       4.0 7.0 NaN   NaN  NaN   NaN

trans1 = pd.concat([cands.reindex(acq.index), acq], join='outer', axis=1)
结果是:
trans1:
        a   b    c  d  A B
order
6      NaN NaN NaN NaN 4 7 
2      20  50  80  110 5 8
1      10  40  70  100 6 9

对比结果,用reindex主要是形成了筛选作用限定了要显示出来的
index的值并限定了顺序

pandas1.0以后把以前的join_axes踢掉,索引顺序默认第一个数据框,
没得索引范围的选择,直接是取索引们的并集(以前是依靠join_axes),
合并后第一个数据框放最左边
若要想指定参照索引范围和顺序,则需要利用reindex改变数据框的索引范围和顺序。
当要合并的数据框们各自的索引一样时,索引顺序会保持,如果索引不一样,则
顺序排列。
版本升级后功能被详细分出来了。

Oracle Related Concept and Syntax

SID: instance_name, unique name of the INSTANCE

https://stackoverflow.com/questions/43866/how-sid-is-different-from-service-name-in-oracle-tnsnames-ora

SID      SERVICE_NAME
bob1    bob
bob2    bob
bob3    bob
bob4    bob

SERVICE_NAMES:Oracle recommends that the value of the service_name be the same as the ORACLE_SID. However, a service_name can point to more than one instance

http://www.dba-oracle.com/t_tns_service_name.htm

set linesize 1000
to have a friendly appearance to look:
https://dolphinpg.net/program/oracle-sqlplus-sql-linesize-column/

sqlplus: sqlplus system@orcl

login orcl instance as system administrator

DROP TABLESPACE TABSP1 INCLUDING CONTENTS AND DATAFILES;

adding AND DATAFILES makse sure the datafiles also be deleted.

DROP TABLESPACE TABSP1 INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS;

CASCADE CONSTRAINTS makes sure the constraints also be deleted.

ALTER TABLESPACE TABSP1 ADD DATAFILE 'D:\ORCL\DBFILE2.DBF' SIZE 100M;

eg: alter tablespace tablespacename add datafile 'D:\xxx.DBF' size 10G autoextend on next 100M maxsize unlimited;

ALTER TABLESPACEADD DATAFILE to add more corresponding physical files to save it.

DROP USER SPOTFIRE_DB CASCADE;

delete the user named spotfire_db within all the tablespace under it.

Sqlplus /nolog: without log, which is safe to protect the password

conn Username/Password@Servicename

SQL> conn sys/ as sysdba;

conn sys/PW@instance_name as sysdba

login in using a user

SELECT * from sn_version;  contains the version details for the product.

http://informatics.perkinelmer.com/Support/KnowledgeBase/details/Default?TechNote=3079

create user name identified by password;

create user named name with password

https://blogs.oracle.com/sql/how-to-create-users-grant-them-privileges-and-remove-them-in-oracle-database

GRANT ALL PRIVILEGES to username; 

grant all authority to a user

How to Grant All Privileges to a User in Oracle

CREATE TABLE CardInfo (
CardID nchar(6) NOT NULL,
CustomerID nchar(5),CONSTRAINT pk1 PRIMARY KEY(CardID)
);

let the CardID becomes the pk1 primary key

copy the table from another table

CREATE TABLE emp
AS SELECT * FROM test;

https://sql-oracle.com/?p=1694

INSERT INTO CardInfo (
  CardID, CustomerID)
VALUES (
  'AX10012', 'MASUU12'
);

CREATE TABLE TBL1 (NOTE VARCHAR2(10)) TABLESPACE TABSP;

means create a table named tbl1 with the column information and belonged to the tablespace named tabsp, and, under the schema, the username who having logined in the oracle.

COMMIT;

quit: is to quit database system

Two connection styles:

ODBC(Open Database Connectivity): through database connector

JDBC(Java Data Base Connectivity):through information link

https://blog.csdn.net/u010926964/article/details/46389867

Tnsnames.ora: it is the driver configuration file

select userenv('language') from dual;

check the language code used in database.

If you want to Unlock Accounts and Reset Passwords:

https://docs.oracle.com/cd/B19306_01/install.102/b25300/rev_precon_db.htm

sqlplus /nolog

CONNECT SYS/SYS_password AS SYSDBA

make sure to set SEC_CASE_SENSITIVE_LOGON = TRUE;

try UTF-8 when import data in oracle sql developer, then it won’t be 文字化け.

中文乱码解决:https://www.geek-share.com/detail/2765805380.html

DROP TABLE table1 CASCADE CONSTRAINTS;

delete the table named table1 in the database

delete the table1 totally:

DROP TABLE table1 PURGE;

https://sql-oracle.com/?p=373

SELECT * FROM RECYCLEBIN;

choose the recyclebin

PURGE RECYCLEBIN;

clean the recyclebin forever

SELECT VALUE FROM V$PARAMETER WHERE NAME = ‘spfile’;

to check whether you use SPFILE to configure the initial parameters.

tnsnames.ora is in dbhome_1\network\admin

listener.ora is in dbhome_1\network\admin

SID is saved in memory, and database file(.dbf) is saved in ORCL folder

SID’s name can be checked from windows service, eg. OracleServiceORCL

database file name is written in parameter of DB_NAME in the initial spfile

The process of data refreshment:

1.INSERT/UPDATE/DELETE->Redo log Buffer, Database buffer cache,

2.COMMIT->Redo log file

3.while checkpoint happen(when redo log file refresh, create, or instance shutdown), database buffer cache->dbf file

ROWID resembles the key of the row in each datatable, and it cannot be changed mannualy but automatically allocated by system. It is a must to ask the rowid clearly, eg.

SELECT rowid,empno FROM emp;

To look for the version of Oracle:

SELECT * FROM V$VERSION;

sqlplus / as sysdba(short style for the next one)

sqlplus user1/pass1 as sysdba(used the login information)

shutdown the database: sqlplus->shutdown immediate

startup the database: sqlplus->startup

NOMOUNT・・・read the initial parameter->STARTUP NOMOUNT
MOUNT・・・read the redo log file, path, etc.->STARTUP MOUNT
OPEN・・・read the .dbf file, open state->STARTUP

sqlplus username/password@orcl

run by quote from file:

@d:\test\emp.sql;

@d:\test\emp_para.sql 'A009', 'XXX', 'TO1';

start with the command:

sqlplus username/password@orcl @d:\test\emp.sql;

CREATE OR REPLACE DIRECTORY dp_dir AS 'd:\dump';

means let the dp_dir to ‘d:\dump’

drop directory dp_dir;

means delete directory dp_dir

GRANT READ ON DIRECTORY dp_dir TO test;

means give the test the authority to read the dp_dir

GRANT WRITE ON DIRECTORY dp_dir TO test;

means give the test the authority to write the dp_dir

The command below is used in command prompt, which is to copy all the database file content to somewhere.

expdp username/password@orcl directory=dp_dir dumpfile=dmp_db.dmp log=exp.log FULL=Y

to select a certain time when export, use flashback_time:

FLASHBACK_TIME=”TO_TIMESTAMP(’12-02-2005 14:35:00′, ‘DD-MM-YYYY HH24:MI:SS’)”

systimestamp gets the current time: https://www.techonthenet.com/oracle/functions/systimestamp.php

remap_schema maps the old schema to new shcema:

https://blog.csdn.net/e_wsq/article/details/78374020

eg:

  1. expdp system/password@servicename directory=data_pump_dir dumpfile=xxx.dmp schemas=xxx flashback_time=systimestamp logfile=xxx.log
  2. impdp system/password@servicename directory=data_pump_dir dumpfile=xxx.dmp remap_schema=(oldschema1:newschema1,oldschema2:newschema2) logfile=xxx.log
  3. EXPDP system/password@servicename DIRECTORY=xxx DUMPFILE=xxx.dmp LOGFILE=xxx.log SCHEMAS=xxx
  4. IMPDP system/password@servicename DIRECTORY=xxx DUMPFILE=xxx.dmp LOGFILE=xxx.log SCHEMAS=xxx

use TABLESPACES=tabsp1 to instead of FULL=Y, action on only the tablespaces

use SCHEMAS=test to instead of FULL=Y, action on only the schemas

use TABLES=test.emp to instead of FULL=Y, action on only the tables

option: https://sql-oracle.com/?p=183

CONTENT=data_only(other wise METADATA_ONLY, ALL)

TABLE_EXISTS_ACTION = REPLACE(other wise SKIP, APPEND, TRUNCATE)

Phisically Backup file:

init.ora

.ctl(control file)

.dbf

.log(redo log)

SCN(system change number):

check the SCN in .dbf and .ctl is the same to judge whether the content is the same

To recover the SCN and keep the SCN the same from the redo log file:

recovery automatic database;

then open it as usual state:

alter database open;

to show all the directory objects:

SELECT * FROM DBA_DIRECTORIES;

alert_orcl.log:(app\oracle\diag\rdbms\orcl\orcl\trace)

used to record the alert, start on or off log, log switch

listener.log:(app\oracle\diag\tnslsnr\LAPTOP-DPQM9JLI\listener\trace)

access to listener’s information

To check if archive log exists:

SELECT LOG_MODE FROM V$DATABASE;

SELECT NAME, VALUE FROM V$PARAMETER WHERE NAME LIKE 'log_archive%';

Procedure to use archivelog:

1.SHUTDOWN IMMEDIATE;

2.STARTUP MOUNT;

3.ALTER SYSTEM SET LOG_ARCHIVE_DEST_1=’LOCATION=D:\ORACLE\ORADATA\ARCHIVE’;

4.ALTER DATABASE ARCHIVELOG;

5.ALTER DATABASE OPEN;

RMAN‘s usage to delete the archivelog automatically: https://sql-oracle.com/?p=1555

TEMPORARY TABLE, which is used by group, sort, or calculation in caches

CREATE TABLESPACE TABSP DATAFILE 'D:\oradata\orcl\TABSP1.dbf' SIZE 300M AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED;

CREATE TEMPORARY TABLESPACE TMPSP TEMPFILE ‘TempFile1.dbf SIZE 100M;

The above is to create tablespace named tabsp, showing the file path, size, which is able to extend(For tempfile, add TEMPORARY and use TEMPFILE instead of DATAFILE in the command)

CREATE TABLESPACE TABSP DATAFILE
'
D:\oradata\orcl\TABSP1.dbf' SIZE 300M AUTOEXTEND OFF;

This makes the size maximum be 300M

CREATE TABLESPACE TABSP DATAFILE
'D:\oradata\orcl\TABSP1.dbf' SIZE 300M
AUTOEXTEND ON NEXT
100M MAXSIZE UNLIMITED,
'
D:\oradata\orcl\TABSP2.dbf' SIZE 300M
AUTOEXTEND ON NEXT
100M MAXSIZE UNLIMITED;

It can be even put into 2 more files.

ALTER DATABASE DATAFILE 'D:\oradata\TABSP1.dbf' RESIZE 500M;

change the size of the datafile for a tablespace, only available to shrink the size when there is no data inside.

Change it to automatically extend the datafile:

ALTER DATABASE DATAFILE 'D:\APP\TEST\ORADATA\ORCL\TABSP1.DBF'
AUTOEXTEND ON NEXT 100M
MAXSIZE UNLIMITED;

to check the autoextensible state:

SELECT TABLESPACE_NAME, FILE_NAME, AUTOEXTENSIBLE
FROM DBA_DATA_FILES
ORDER BY 1

to check the table datafile volume, etc:https://sql-oracle.com/?p=375

but better to use sqldeveloper as the video below(make sure to use the account having the privilege)

ALTER TABLE TBL1 MOVE TABLESPACE TABSP1;

that means to move table tbl1 to another tablespace named tabsp1

ALTER TABLE TEST1 MOVE;

make the table be quick.https://sql-oracle.com/?p=360

ALTER INDEX index1 REBUILD TABLESPACE idxsp2;

change the index’s tablespace(need rebuild the index)https://sql-oracle.com/?p=279

ALTER INDEX index1 REBUILD;

as the corresponding index of that column needs to rebuild

to check the index is valid or not:

SELECT INDEX_NAME,TABLE_OWNER,TABLE_NAME,STATUS FROM USER_INDEXES;

to check whether the dbf file is broken or not in command prompt(not used for temp file):

DBV FILE=D:\ORACL\ORADATA\TBSP1.DBF

schema resembles the container which is paired with a special user in Oracle, schema contains the table, view, etc.

CREATE USER SATOU IDENTIFIED BY PASS;

The above is to create user, and the schema is meanwhile created by Oracle.(Living together, dying together)

SELECT * FROM schema_name.table_name;

cannot omit, if login in another username, which is different from schema_name’s username

SELECT SYSDATE FROM DUAL;

SELECT ROUND(10.5) FROM DUAL;

dual is under sys schema, having some convenient use

change the table name:

ALTER TABLE table1 RENAME TO table2;

change the empname’s number of digits:

ALTER TABLE table1 MODIFY (empname VARCHAR2(20));

SELECT * FROM ALL_TAB_COLUMNS
WHERE OWNER = ‘XX’;https://sql-oracle.com/?p=358

SELECT TABLE_NAME,COLUMN_NAME,DATA_TYPE,DATA_LENGTH,DATA_PRECISION,DATA_SCALE
FROM ALL_TAB_COLUMNS
WHERE OWNER = ‘username’ AND TABLE_NAME = ‘tablename’;

username and tablename is Case Sensitive!!!

CREATE USER username
IDENTIFIED BY password
DEFAULT TABLESPACE TABSP1
TEMPORARY TABLESPACE TEMP
QUOTA UNLIMITED ON TABSP1
QUOTA UNLIMITED ON TABSP2;

If use 2 tabspace, using quota command above to show ithttps://sql-oracle.com/?p=193

ALTER TABLE TEST1 ADD(ADDITION NUMBER(5,0), ADDITION2 VARCHAR2(100));

add some columns into the old table.

ALTER TABLE TEST1 RENAME COLUMN addition TO addition1;

change the column name.

ALTER TABLE TEST1 MODIFY (ADDITION1 VARCHAR2(10));

change the column’s data type

ALTER TABLE TEST1 DROP (ADDITION1) CASCADE CONSTRAINTS;

delete a column in the table

CREATE INDEX INDEX1 On TEST1(ADDITION2) TABLESPACE tablespacename;

create an index on a column

DROP INDEX index1;

delete a index(if you want to change it, you can only delete and rebuild it)

ALTER TABLE test1 MODIFY col1 NULL;???

change the column to be nullable

CREATE OR REPLACE VIEW view’sname AS

SELECT…

create a view…

DROP VIEW viewname CASCADE CONSTRAINTS;

delete a view

ALTER TABLE table1 ADD CONSTRAINT pk1 PRIMARY KEY (empno,depno);

add empno and depno as the primary key of table1

ALTER TABLE table1 DROP CONSTRAINT pk1;

delete the primary key(if you want to change it, you can only delete and rebuild it)

change user’s password:

ALTER USER satou IDENTIFIED BY pass1;

check the locked user:

SELECT USERNAME,ACCOUNT_STATUS,LOCK_DATE
FROM DBA_USERS
WHERE ACCOUNT_STATUS <> ‘OPEN’;

unlock the locked user:

ALTER USER satou ACCOUNT UNLOCK;

about making profile: https://sql-oracle.com/?p=387

check the profile condition on users:

SELECT USERNAME,PROFILE FROM DBA_USERS;

apply profile on a user.

ALTER USER satou PROFILE profile1;

creat a role:

CREATE ROLE ROLE1;

delete a role:

DROP ROLE role1;

define the role:

GRANT INSERT,UPDATE,DELETE ON TABLE_A TO ROLE1;

give the user a role:

GRANT role1 TO user1;

withdraw a role form the user:
REVOKE role1 FROM user1;

To delete the role content:

1.REVOKE create table FROM role1;

2.REVOKE create table,drop table FROM role1,role2;

3.REVOKE insert ON table1 FROM role1;

4.REVOKE all ON table1 FROM role1;

to check all the defined roles(needs the privilege):

SELECT * FROM DBA_ROLE_PRIVS;

SELECT USERNAME,STATUS,OSUSER,MACHINE,LOGON_TIME
FROM V$SESSION
WHERE USERNAME IS NOT NULL;

The above is to get the information of current session.https://sql-oracle.com/?p=266

to check the session and the process maximum:

SELECT * FROM V$RESOURCE_LIMIT
WHERE RESOURCE_NAME = ‘processes’
OR RESOURCE_NAME = ‘sessions’;

to check all the username can be seen by current logined user:

SELECT * FROM ALL_USERS
ORDER BY USERNAME;

more user information in detail:

SELECT USERNAME,ACCOUNT_STATUS,DEFAULT_TABLESPACE,TEMPORARY_TABLESPACE,PROFILE
FROM DBA_USERS
ORDER BY USERNAME;

give the privilege to create table:

GRANT CREATE TABLE TO SATOU;

give the privilege to insert on table:

GRANT INSERT ON TABLE_A TO SATOU;

check the sysdba role: SELECT * FROM V$PWFILE_USERS;

check the dba role: sysdba>dba role

SELECT * FROM DBA_ROLE_PRIVS
WHERE GRANTED_ROLE ='DBA';

If using spfile mode(only spfile needs restart) to change the processes and sessions maximum:https://sql-oracle.com/?p=395

ALTER SYSTEM SET PROCESSES = 1000 SCOPE=SPFILE;
ALTER SYSTEM SET SESSIONS = 1000 SCOPE=SPFILE;

size change of SGA(System Global Area, needs restart):

ALTER SYSTEM SET SGA_MAX_SIZE = 1G SCOPE=SPFILE;
ALTER SYSTEM SET SGA_TARGET = 1G SCOPE=SPFILE;

to confirm SGA:

show parameter sga_;

size change of PGA(Program Global Area, needs restart):

ALTER SYSTEM SET PGA_AGGREGATE_TARGET = 500M SCOPE=SPFILE;

to confirm PGA:

SHOW PARAMETER TARGET;

After Oracle 11gR2, the memory distribution is automated, without setting sga_target and pga_aggregate_target seperately using the command as follows, then reboot the oracle service:eg:

create spfile=’C:\app\Administrator\virtual\product\12.2.0\dbhome_1\database\SPFILEORCL.ORA’ from pfile=’C:\app\Administrator\virtual\admin\orcl\pfile\init.ora’;
alter system set sga_target=0 scope=spfile;
alter system set pga_aggregate_target=0 scope=spfile;
alter system set memory_target=16G scope=spfile;
alter system set memory_max_target=24G scope=spfile;

make synonym for table:

CREATE SYNONYM othername FOR tablename;

make public synonym for table(available for all users):

CREATE PUBLIC SYNONYM othername FOR tablename;

to check the synonym in the database:https://sql-oracle.com/?p=211

SELECT OWNER, SYNONYM_NAME ,TABLE_NAME FROM ALL_SYNONYMS;

database link(use to connect the database on another server):

CREATE DATABASE LINK databaselinkname
CONNECT TO username
IDENTIFIED BY password
USING 'database_name';

‘database_name’ is written in tnsnames.ora

to use the data by database link:

SELECT * FROM username.tablename@databaselinkname;

check all the databaselink:https://sql-oracle.com/?p=213

SELECT * FROM DBA_DB_LINKS;(more in detail)

SELECT * FROM ALL_DB_LINKS;

to delete the database link:

DROP DATABASE LINK databaselink_name;

DROP PUBLIC DATABASE LINK databaselink_name;

trigger: do something before/after/instead of, seems like to build a link mechanismhttps://sql-oracle.com/?p=147

CREATE OR REPLACE TRIGGER TRI1
BEFORE/AFTER/INSTEAD OF
INSERT OR UPDATE
ON EMP
FOR EACH ROW
BEGIN
PRO_A
END;

for each row means do the trigger in every row action

to check the trigger information:https://sql-oracle.com/?p=1543

SELECT TRIGGER_NAME, TABLE_NAME, STATUS FROM USER_TRIGGERS;

SELECT TRIGGER_BODY FROM ALL_TRIGGERS;

change the trigger state:

ALTER TRIGGER triggername DISABLE;
ALTER TRIGGER triggername ENABLE;

change the trigger states which involve in the table:

ALTER TABLE tablename DISABLE ALL TRIGGERS;
ALTER TABLE tablename ENABLE ALL TRIGGERS;

to give the privilege involves job:

GRANT CREATE JOB TO user1;
GRANT MANAGE SCHEDULER TO user1;

create automated job execution:https://sql-oracle.com/?p=164

BEGIN

DBMS_SCHEDULER.CREATE_JOB
(
job_name => ‘JOB_PROC_A’,
job_type => ‘STORED_PROCEDURE’,
job_action => ‘USER1.PROC_A’,
start_date => TO_DATE(‘2018/08/01 00:00:00′,’yyyy/mm/dd hh24:mi:ss’),
repeat_interval => ‘FREQ=HOURLY’,
enabled => TRUE
);

END;

oracle’s procedure:https://sql-oracle.com/?p=1083

CREATE OR REPLACE PROCEDURE proA
IS
nCnt NUMBER;
rEmp emp%ROWTYPE;
tEmpNo emp.empno%TYPE;
BEGIN
nCnt := 1;
rEmp.empno := ‘A0101’;
tEmpNo := ‘A0101’;
END;

if there is prameter:

CREATE OR REPLACE PROCEDURE proA(nEno IN NUMBER)
IS
nCnt NUMBER;
BEGIN
UPDATE emp
SET salary = salary * 2
WHERE empno = nEno;
END;

oracle’s function:

CREATE OR REPLACE FUNCTION funA RETURN NUMBER
IS
nCnt NUMBER;
BEGIN
nCnt := 1;
RETURN nCnt;
END;

or if there is parameter:

CREATE OR REPLACE FUNCTION funA(nEno IN NUMBER) RETURN NUMBER
IS
nSal NUMBER;
BEGIN
SELECT salary INTO nSal FROM emp
WHERE empno = nEno;
RETURN nSal;
END;

DROP PROCEDURE pro1;
DROP FUNCTION fun1;
DROP PACKAGE pac1;

the usage of loop:

(1.loop exit when):

CREATE OR REPLACE PROCEDURE proA
IS
nCnt NUMBER;
BEGIN
LOOP

nCnt := nCnt + 1;
EXIT WHEN nCnt > 10;
END LOOP;
END;

(2.while loop):

CREATE OR REPLACE PROCEDURE proA
IS
nCnt NUMBER;
BEGIN
WHILE (nCnt <= 10);
LOOP
nCnt := nCnt + 1;
END LOOP;
END;

(3.for loop):

CREATE OR REPLACE PROCEDURE proA
IS
nCnt NUMBER;
BEGIN
FOR nCnt IN 1 .. 10
LOOP
nCnt := nCnt + 1;
END LOOP;
END;

the usage of if:

1.

IF nEmpNo > 100 THEN
nCnt = 1;
END IF;

2.

IF nEmpNo > 100 THEN
nCnt = 1;
ELSIF nEmpNo < 10 THEN
nCnt = 0;
END IF;

3.

IF nEmpNo > 100 THEN
nCnt = 1;
ELSIF nEmpNo < 10 THEN
nCnt = -1;
ELSE
nCnt = 0;
END IF;

the usage of case:

CASE
WHEN nEmpNo > 100 THEN
nCnt = 1;
WHEN nEmpNo < 10 THEN
nCnt = -1;
ELSE
nCnt = 0;
END CASE;

EXECUTE IMMEDIATE(PL/SQL)OracleのEXECUTE IMMEDIATE 動的SQL【PL/SQL】

number type:【Oracle】NUMBER 数値型の特徴

NUMBER(6,2):6 digits in total, 2 after decimal point

NUMBER(3,-2):two zero before decimal point, maximum three digits before decimal point

change from character to number:

SELECT TO_NUMBER(‘10.5’) FROM DUAL;

round:

SELECT ROUND(10.5) FROM DUAL;

SELECT ROUND(10.437,2) FROM DUAL;

SELECT ROUND(151.437,-2) FROM DUAL;

The above is to round the decile number.OracleのROUND 数値を四捨五入する【SQL】

truncate the unrequired:OracleのTRUNC 数値を切り捨てる【SQL】

SELECT TRUNC(10.5) FROM DUAL;
SELECT TRUNC(10.437,2) FROM DUAL;
SELECT TRUNC(151.437,-2) FROM DUAL;

ABS:

SELECT ABS(-10) FROM DUAL;

MOD:

SELECT MOD(9,2) FROM DUAL;

POWER:

SELECT POWER(5,3) FROM DUAL;

STDDEV:

SELECT STDDEV(COLUMNNAME) FROM TABLENAME;

data type:OracleのVARCHAR・CHAR 文字データ型の特徴

VARCHAR2(10)

10 can be saved less than 10, if put into a smaller strings, the most common one

NVARCHAR2 is for unicode

CHAR(10) is saved as 10, even if it is less than 10

NCHAR is for unicode

RAW is for Binary data, length is extendable OracleのBLOB・BFILE バイナリデータ型の特徴

LONG RAW is for pictures, audios, etc, better to use BLOB instead

BFILE saves the information of the path to a file

CLOB is for text data, NCLOB is for Unicode especially OracleのCLOB・NCLOB テキストデータ型の特徴

string to date:

SELECT TO_DATE(‘20171201‘,’YYYY/MM/DD’) FROM DUAL;

SELECT TO_DATE(‘20171201230010‘,’YYYY/MM/DD HH24:MI:SS’) FROM DUAL;

to concat:

1.SELECT CONCAT(‘A‘,’B‘) FROM DUAL;

2.SELECT ‘A‘ || ‘B‘ FROM DUAL;

to replace:SATOU->KATOU

SELECT REPLACE(‘SATOU‘,’S‘,’K‘) FROM DUAL;

SATOU->SATO

SELECT REPLACE('SATOU','U') FROM DUAL;

SELECT REPLACE('ABC','BC','XY') FROM DUAL; ABC->AXY

to translate: ABC->XBY Oracle TRANSLATE 文字列を1文字ずつ置換する

SELECT TRANSLATE('ABC','AC','XY') FROM DUAL;

to see the dedault profile limit state:

select resource_name, limit from dba_profiles where profile='DEFAULT';

change the default profile and let the password have no lock time:https://cloud.tencent.com/developer/article/1529149

alter profile default limit
password_life_time unlimited
password_lock_time unlimited
password_grace_time unlimited
failed_login_attempts unlimited

#session should be(=>300)

show parameter session;

#process should be(=>300)

show parameter processes;

#cursor should be(=>500)

show parameter open_cursor;

#change cursor, will be effective after restart

alter system set open_cursors=500 scope=spfile;

list all the schemas in database:

select username from dba_users;

check the DATA_PUMP_DIR:

desc dba_directories

select directory_name, directory_path from dba_directories;

show the current logined user:

show user

to check the NLS_CHARACTERSET code while installing oracl database:

select * from nls_database_parameters;

to check the installment configuration:

app\oracle\product\19.3.0\dbhome_1\cfgtoollogs\oui

pfile locates in: app\oracle\admin\orcl\pfile

connect by jdbc:

jdbc:oracle:thin:@hostname:1521:servicename

or

oracle:thin:@hostname:1521/servicename

check the service of oracle available, and description for alias in command prompt:

tnsping servicename

check the listener’s state in command prompt:

lsnrctl status

start or stop the listener:

lsnrctl start

lsnrctl stop

show all the table under a certain schema:

select table_name from USER_TABLES;

to open PDB(pluggable database, default pdb’s instance name is orclpdb):

sqlplus / as sysdba
check the sate:
select con_id,name,open_mode from v$pdbs;
and then:
alter pluggable database ORCLPDB open;
alter session set container=ORCLPDB;
commit;
restart the database

check the connected container:
SQL> show con_name;
check the pdb name:
SQL> select pdb_name from cdb_pdbs;
connect to the pdb:
SQL> alter session set container = ORCLPDB;

to keep it starts with the windows server startup, you need to save the PDB’s state:

alter pluggable database orclpdb save state;

Check tablespace in db:

select tablespace_name from dba_tablespaces;

Check username in db:

select username from dba_users;

remap tablespace, eg:

impdp system/PW@instance_name directory=data_pump_dir dumpfile=xxx.dmp remap_tablespace=(old_tablespace_name1:new_tablespace_name1,  old_tablespace_name2:new_tablespace_name2) remap_schema=old_schema:new_schema logfile=xxx.log

to output csv by sql script and in a good format, under sqlplus:

set echo off
set termout off
set heading on
set linesize 32767
set trimspool on
set colsep ‘,’
set underline off
set feedback off
set pagesize 0 embedded on
set pause off
set mark csv ON
spool “result.txt”
@ “xxx.sql”
spool off

check the tablespace’s datafile size in physical hard disk:

select tablespace_name,file_name,bytes/1024/1024/1024"GB" from dba_data_files;

create directory for importing and exporting dumpfile:

create directory xxx as 'C:\foldername';

show which instance it is using when the oracle is in cluster:

select * from v$instance;

show error of a certain view:

show errors view schemaname.viewname;

compile a view to check error:

alter view schemaname.viewname compile;

check which segment the schema has:

select segment_name, tablespace_name from dba_segments where owner=‘schemaname‘;

check which object the schema has, including view:

select object_name,object_type from dba_objects where owner=’schemaname‘;

check which table the schema has: oracleの表領域が少なくなった場合の調査用SQL

select table_name,tablespace_name from all_tables where owner=’ schemaname ‘;

find data file folder in hard disk:

select * from dba_data_files ;

check the os where oracle installed on:

select platform_name from v$database;

get the hostname where oracle installed on:

select * from v$instance;

To clear the SQL window:

cl scr;

to solve error ORA-01033, if accidentally delete the tablespace file on the hard disk:

Oracle ORA-01033: 错误解决办法

check the last command in the buffer: ed

check data file volume usage:

SELECT
  A.TABLESPACE_NAME "Table Space"
  , ROUND(SUM(BYTES) / 1024 / 1024, 1) "File Volume(MB)"
  , ROUND(SUM(BYTES - SUM_BYTES) / 1024 / 1024, 1) "Used Volume(MB)"
  , ROUND(SUM(SUM_BYTES) / 1024 / 1024, 1) "Free Volume(MB)"
  , ROUND((SUM(BYTES - SUM_BYTES) / 1024) / (SUM(BYTES) / 1024) * 100, 1)
    "Used(%)" 
FROM
  DBA_DATA_FILES A 
  LEFT JOIN  ( 
    SELECT
      TABLESPACE_NAME
      , FILE_ID
      , NVL(SUM(BYTES), 0) SUM_BYTES   
    FROM
      DBA_FREE_SPACE 
    GROUP BY
      TABLESPACE_NAME
      , FILE_ID
  ) B 
    ON A.TABLESPACE_NAME = B.TABLESPACE_NAME 
    AND A.FILE_ID = B.FILE_ID 
GROUP BY
  A.TABLESPACE_NAME 
ORDER BY
  1;

check all the tablespace:

SELECT TABLESPACE_NAME, STATUS, CONTENTS From user_tablespaces;

create tablespace:

CREATE TABLESPACE [yourTablespaceName] DATAFILE '[pathTo\xxx.dbf]' SIZE 300M AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED;

create temporary tablespace:

CREATE TEMPORARY TABLESPACE [yourTemporaryTableSpaceName] TEMPFILE '[pathTo\xxx.dbf]' SIZE 300M AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED;

create schema and assign it to certain tablespaces:

CREATE USER [yourUserName] IDENTIFIED BY [yourPassword] DEFAULT TABLESPACE [yourTableSpaceName] TEMPORARY TABLESPACE [yourTemporaryTableSpaceName];

delete the tablespace within the contents inside. (If there is data inside, including contents is a must):

DROP TABLESPACE [yourTableSpaceName] INCLUDING CONTENTS;

grant quota on tablespace to a user: (A quota only really makes sense for permanent extents)

ALTER USER [yourSchemaName] QUOTA UNLIMITED ON [yourTableSpaceName];

create session system privilege:

GRANT CREATE SESSION TO [yourSchemaName];

Pyinstaller —Failed to execute script的对策

pyinstaller --hidden-import=pkg_resources.py2_warn --onefile XXX.py
这样就可以生成了

如果ico文件放在和py同一目录下,生成带有DIY图标的exe文件:
pyinstaller --icon=XXX.ico --hidden-import=pkg_resources.py2_warn --onefile XXX.py

如果是不带窗口:
pyinstaller --hidden-import=pkg_resources.py2_warn --onefile --noconsole XXX.py

Heroku的配置

1.上传环境: pip3 freeze > requirements.txt

2.设置python版本号内容放在runtime.txt里

3.设置settings.py

4.设置Procfile

5.放置placeholder.txt占位

6.git config –global user.name “XXX”

7.git config –global user.email “XXX”

8.git init

9.git add .

10.git commit -am “Updated project to use WhiteNoise.”

11.git status

12.heroku login

13.heroku create

14.heroku config:set DISABLE_COLLECTSTATIC=0(heroku服务器已经有一个静态文件占位了,所以要删掉它)

15.git push heroku master

16.heroku ps

17.heroku open

通过 WordPress.com 设计一个这样的站点
从这里开始