`
lovejuan1314
  • 浏览: 341816 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

一个特简单的linux shell scripting

阅读更多
#!/bin/sh
#FM
#2008-08-26
#This script will batch insert data into partitioned views table per 90 000
#It will import all of old_views data into views
#the old_views contains 398372489 rows
#
v_startID=1
v_endID=900000
v_seq=900000
v_begin=1
for ((i=1;i<443;i++))
do
psql adchap_dataware << Foo
BEGIN;
INSERT INTO views SELECT * FROM old_views where id >= $v_startID  and id <= $v_endID;
COMMIT;
Foo
v_startID=$(($v_endID+$v_begin))
v_endID=$(($v_endID+$v_seq))
echo $v_startID $v_endID
done


其实就是批量将旧表数据导入到新的分区表中而已。用java做特简单但是服务器没有jre环境。

用plpgsql写的话,缺点是旧表数据达到4亿,这样批量执行的话,这个函数是全部写完后作为一个事务提交的,这样很容易得到
ERROR:  cannot have more than 2^32-1 commands in a transaction

因为分区表中有触发器,会根据时间判断放入到什么分区表中的

--Import Data to table partition
CREATE OR REPLACE FUNCTION BatchInsertViews(IN startID integer,IN totalNo integer) RETURNS integer AS $$
DECLARE
  v_startID integer;
  v_endID   integer;
  v_seqNo   integer;
  v_no      integer;
    
BEGIN
	
	v_seqNo := 900000;
	v_no := (totalNo/v_seqNo)+1;
	v_startID := startID;
	v_endID   := v_seqNo;
	FOR i IN 1 .. v_no LOOP
		RAISE NOTICE 'This Should be executed times :%',v_no;
		EXECUTE 'INSERT INTO views SELECT * FROM old_views where id >= ' || v_startID ||' and id <= '|| v_endID;
		v_startID := v_endID + 1;
		v_endID := v_endID + v_seqNo;
		RAISE NOTICE 'StartID Change To :%',v_startID;
		RAISE NOTICE 'EndID Change To :%',v_endID;
	END LOOP;
   
   RETURN 0;
END;
$$ LANGUAGE plpgsql;
分享到:
评论

相关推荐

    Linux Shell Scripting Cookbook(3rd) mobi

    Linux Shell Scripting Cookbook(3rd) 英文mobi 第3版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书

    Linux Shell Scripting Cookbook Third Edition

    Linux Shell脚本手册 - 第三版,. This book will take you through useful real-world recipes designed to make your daily life easier when working with the shell.

    Linux Shell Scripting Bootcamp mobi

    Linux Shell Scripting Bootcamp 英文mobi 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书

    Mastering Linux Shell Scripting

    Shell scripting is a quick method to prototype a complex application or a problem by automating tasks when working on Linux-based systems. Using both simple one-line commands and command sequences ...

    Linux shell scripting cookbook

    Shantanu Tushar从大学时代开始就是一个高级的GNU/Linux用户,工作之余,他热衷于编写Shell脚本来简化工作,提高效率。《Linux Shell Scripting Cookbook》的出版为Linux用户和开发者提供了丰富的资源和灵感,是学习...

    learning linux shell scripting 2nd

    learning linux shell scripting 第二版,经典书 This book is for readers who are proficient at working with Linux and who want to learn about shell scripting to improve their efficiency and practical ...

    Linux Shell Scripting Bootcamp epub

    Linux Shell Scripting Bootcamp 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书

    Mastering Linux Shell Scripting.epub

    Shell scripting is a quick method to prototype a complex application or a problem by automating tasks when working on Linux-based systems. Using both simple one-line commands and command sequences ...

    Mastering Linux Shell Scripting(2nd) mobi

    Mastering Linux Shell Scripting(2nd) 英文mobi 第2版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书

    Linux Shell Scripting Essentials 无水印pdf 0分

    Learn shell scripting to solve complex shell-related problems and to efficiently automate your day-to-day tasks About This Book Familiarize yourself with the terminal by learning about powerful shell...

    Mastering Linux Shell Scripting.mobi

    Shell scripting is a quick method to prototype a complex application or a problem by automating tasks when working on Linux-based systems. Using both simple one-line commands and command sequences ...

    Linux Shell Scripting with Bash

    - 示例:编写一个简单的日志记录脚本,记录操作系统的当前时间: ```bash #!/bin/bash echo "$(date)" &gt;&gt; log.txt ``` - **自动化部署** - 示例:创建一个部署脚本,自动安装软件包并配置服务: ```bash #!...

Global site tag (gtag.js) - Google Analytics